Comments (5)
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.
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 arr
aren't know in the context of the value
form.
from fennel.
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 local
s 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.
Alright good to know! Thanks for the answers!
from fennel.
Hey, I saw you reopened this; is there still an open question here that needs further clarification?
from fennel.
Related Issues (20)
- Incomplete `for` binding table results in bad code generated HOT 1
- Macro treat vararg as first parameter... Unless quoted and unqoted. HOT 5
- Compatibility with Pluto HOT 6
- Cannot use &as with a rest parameter. HOT 2
- Expose the 'varg' function to the compiler environment HOT 4
- `,apropos-doc` cannot find functions defined in REPL HOT 1
- `,apropos-show-docs` not working HOT 1
- Bad code generated in the REPL if the name of a local contains a backslash
- Luau syntax support HOT 4
- [Enhancement] Allow passing special forms as functions in macro context HOT 3
- [Feature Request] Global macro definitions HOT 1
- [Stdlib] Add type check macros HOT 1
- readline support HOT 10
- macro question: access a function's form inside a macro HOT 1
- Creating macro which unpacks arbitrary number of arguments yields incorrect result HOT 2
- Cannot rename argument when using docstring and metadata at the same time in lambda HOT 1
- Line numbers in errors and stack incorrect in `dofile` HOT 2
- Hello! Is about the style.md file on the main repository HOT 4
- REPL doesn't store `gensym`'ed variables? HOT 3
- M HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fennel.