Giter Site home page Giter Site logo

Comments (5)

technomancy avatar technomancy commented on August 11, 2024

There's a few different problems with this. The first problem is that you're stepping thru the list one element at a time when you need to step two at a time. Also you're using each which is meant for side-effects, but in a macro you need to return a form instead. You could use icollect for this, but that would just return a table, which isn't really what you want either. You seem to be trying to emit multiple forms from a single macro, which isn't really something that macros can do; every macro call compiles to a single form.

The good news is you don't need a macro for this:

(local (x y) (values 1 2))

It's already supported with regular local.

Hope that helps.

from fennel.

alecStewart1 avatar alecStewart1 commented on August 11, 2024

That works, but it's just a bit ugly once you get to n amount of local variables in one file, and what if you wanted something like let* in Common Lisp? Say have something odd like this (I don't really know why you would but it's just an example):

(local (mod mapcan arr modified-arr) 
    (values
      (require :mod)
      mod.mapcan
      [1 2 3 4]
      (mapcan arr (fn (n) (* n 2)))))

Again I don't really know why you'd have something like this with this example, mod, mapcan and arraren't know in the context of the value form.

from fennel.

technomancy avatar technomancy commented on August 11, 2024

Sure, once you get beyond 2 or 3 values it's awkward, but at that point there's no longer any reason to do it on one form; you might as well spread it out into multiple locals since it's going to be more than one line anyway by then.

But if you really want to do it in a single form, you could write a macro that accepts your (local! x 1 y 2) notation and emits a single (local (x y) (values 1 2)) form. You don't care about the readability of the macroexpansion.

what if you wanted something like let* in Common Lisp?

The let form in Fennel already works like let* in CL.

from fennel.

alecStewart1 avatar alecStewart1 commented on August 11, 2024

Alright good to know! Thanks for the answers!

from fennel.

technomancy avatar technomancy commented on August 11, 2024

Hey, I saw you reopened this; is there still an open question here that needs further clarification?

from fennel.

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.