@@ -120,6 +120,15 @@ namespace intp::interp {
120120 return list_v->elements [index];
121121 }
122122
123+ static Value list_remove (const std::shared_ptr<List> &list_v, size_t index) {
124+ if (index >= list_v->elements .size ()) {
125+ options_v.logger .error ({}, " runtime error: list index out of range, index is " , index);
126+ }
127+ Value &value = list_v->elements [index];
128+ list_v->elements .erase (list_v->elements .begin () + index);
129+ return value;
130+ }
131+
123132 static void list_append (const std::shared_ptr<List> &list_v, Value value) {
124133 list_v->elements .push_back (std::move (value));
125134 }
@@ -182,6 +191,33 @@ namespace intp::interp {
182191 };
183192 }
184193
194+ static NativeFunction make_list_remove () {
195+ const std::string name = " list_remove" ;
196+ return {
197+ // TODO: Add type checker to replace this manual approach
198+ 2 , name, [name](const std::vector<std::shared_ptr<Thunk> > &args,
199+ const std::shared_ptr<Env> &) -> std::pair<Value, ResultOptions> {
200+ const Value &arg0 = args[0 ]->force ();
201+ if (!std::holds_alternative<std::shared_ptr<List> >(arg0)) {
202+ options_v.logger .error ({}, " runtime error: wrong arguments provided to native function " , name,
203+ " \n " , name,
204+ " signature: List -> Float -> List" " \n "
205+ " runtime error: expected <List> got " , arg0);
206+ }
207+ const Value &arg1 = args[1 ]->force ();
208+ if (!std::holds_alternative<double >(arg1)) {
209+ options_v.logger .error ({}, " runtime error: wrong arguments provided to native function " , name,
210+ " \n " , name,
211+ " signature: List -> Float -> List" " \n "
212+ " runtime error: expected <Float> got " , arg1);
213+ }
214+ return std::make_pair (
215+ Value{list_remove (std::get<std::shared_ptr<List> >(arg0), std::get<double >(arg1))},
216+ ResultOptions{});
217+ }
218+ };
219+ }
220+
185221 static NativeFunction make_list_append () {
186222 const std::string name = " list_append" ;
187223 return {
0 commit comments