Skip to content

Commit

Permalink
fix anonymous fn shorthand bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbicodes committed Sep 5, 2023
1 parent 22fb2c6 commit befac7f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
11 changes: 3 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ import testSuites from './test/tests.json';
import { evalString, deftests, clearTests } from "./src/interpreter"

let editorState = EditorState.create({
doc: `(def client {:name "Super Co."
:location "Philadelphia"
:description "The worldwide leader in plastic tableware."})
(let [{:keys [name location description]} client]
[name location description])`,
doc: `(mapcat #(for [p (k (- i 1) %2)] (conj p %)))`,
extensions: [basicSetup, clojure()]
})

Expand Down Expand Up @@ -170,8 +165,8 @@ function testExercisesUntilFail() {
console.log("Fails:", fails)
}

//testSolution(randExercise())
//testSolution("nth_prime")
testSolution(randExercise())
//testSolution("f")
//loadExercise("all_your_base")
//testExercisesUntilFail()
//testExercises()
6 changes: 2 additions & 4 deletions src/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,11 @@ function _EVAL(ast, env) {
// Anonymous function shorthand
if (types._list_Q(a1)) {
let fun = [types._symbol('fn')]
var args = Array.from(new Set(ast.toString().match(/%\d?/g))).map(types._symbol)
var args = Array.from(new Set(ast.toString().match(/%\d?/g))).map(x => types._symbol(x))
let body = ast.slice(1)[0]
fun.push(args)
fun.push(body)
var lambda = types._function(EVAL, Env, body, env, args, a0);
lambda.lambda = true
return lambda
return types._function(EVAL, Env, body, env, args);
}
case "def":
var res = EVAL(a2, env);
Expand Down

0 comments on commit befac7f

Please sign in to comment.