Replies: 3 comments 5 replies
-
|
Because it's a macro - it's behaving exactly as macros do. If you put a macro in a loop, it does not evaluate the macro Everytime though the loop, it evaluates once during compilation. |
Beta Was this translation helpful? Give feedback.
-
|
Starting from your first example, the easiest solution is to not make def-with-sys a macro, and instead programmatically add bindings to the environment. Functions like defglobal will do what you want. |
Beta Was this translation helpful? Give feedback.
-
|
Ok, guessing what you are trying to do, you can look at spork/path for a similar example. https://github.com/janet-lang/spork/blob/master/spork/path.janet |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If one were to look over at jsys, one can see that the C code basically exports Janet function bindings under a system specific prefix. When one compiles it on their system, if their system is a *nix, it'll be
sys/nix/$functionbut if they were on Windows (which in jsys is currently undefined at this time) it would besys/windows/$function.The idea is for there to be a
sys.janetfile that wraps the system specific functions and one big thing is when thesys.janetfile loads it needs to check what OS it's under and then generate shortnames for thesys/$os/$functionset.The idea here was to have a macro we'll call
def-with-sysand have it do something like the following:The trouble I've ran into is how to get a macro to take a value, mutate it, then tell
defto bind something to the value stored in a variable, where something should be a function.One half working (but bad implementation) resulted in having to manually call the macro for each name:
When I basically copied out the relevant into an REPL and played around with trying to get it to do something, I realized when doing
eachit was trying to bind "sys/os/binding" instead of "sys/os/$binding". I've sense attempted far more ways and none have ended up working witheachbut all were based around the assumption I'd be passing the macro quoted symbols, which I'm figuring out I probably shouldn't do (thanks @pepe). I'll update this as I go along but if anyone has any great ideas I'd definitely welcome the help!Another one, that doesn't work with
each, and doesn't accept quoted symbols:Beta Was this translation helpful? Give feedback.
All reactions