GithubHelp home page GithubHelp logo

Comments (3)

kanaka avatar kanaka commented on September 26, 2024

I think you have a couple of typos. You test function is missing some parens:

(def! test (fn* [l m n] (l m n)))

And your fls function has an incorrect variable name:

(def! fls (fn* [t f] f))

Making those changes I get the correct behavior.

from mal.

igravious avatar igravious commented on September 26, 2024

Ninja edited my typo up above, that wasn't the issue. It seems () around multiple variables gives me the correct behaviour. Is that Lispful that I need () around multiple variables? For what it's worth Haskell doesn't need them though that may be no indication. let test = (\l -> \m -> \n -> l m n)

from mal.

kanaka avatar kanaka commented on September 26, 2024

Parens in Lisp define lists. However, when an unquoted list is evaluated in Lisp, the first position in the list is a function and the rest of the elements are arguments. So (+ 2 3) means call the + function using the arguments 2 and 3. In mal, (fn* (a b) (+ a b)) means define an anonymous function that takes two arguments and calls + using those arguments. This (fn* (a b) + a b) is quite different. That's an anonymous function containing three elements that are not in a list. Mal only uses the first element in the function body so it's really equivalent to this: (fn* (a b) +). When you invoke/apply that function you'll just get what + evaluates to. In other words, this ( (fn* (a b) +) 7 8) will invoke/apply the anonymous function, the + symbol will be evaluated to the native function for addition which will be returned.

It's late at night and I'm tired, so the above explanation might be a bit rambling, let me know if it doesn't make sense and I'll try and give a better answer tomorrow after some sleep.

from mal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.