-
Notifications
You must be signed in to change notification settings - Fork 267
allow a function to store a value #2442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
sorry, I didn't get the difference |
the internal logic is the same, it just does not resolve the variable by Lines 1533 to 1542 in 1ed152a
switch(argv->ex_type) {
case ET_SYM:
if (argv->ex_flags & EX_F_TSYM)
optr->ex_ptr = gensym(argv->ex_ptr);
else
optr->ex_ptr = argv->ex_ptr;
return; |
Well, sorry, I'm really confused. Are you saying you did create a new function named function? Or is this just a PR that closes #2431 ? Meaning, if the PR is taken, can [expr var(a) = 2.5] work and set [v a] to '2.5' when taking a bang? |
i'm not sure whether i groked to assign values to symbols defined at run-time, how about using a
|
after reading the code, i see that the problem is actually just one of bad wording in the description of this PR.
i still think an |
Assign makes more sense, or var could just take one or two arguments. If two, the second is assigned to the first |
sorry for not being clear, i wasnt decided on the name thats why i wrote 'function', but your 'assign' actually makes more sense! and is considerably less messy |
assign makes more sense, but I would avoid creating a new function altogether, and I like my idea of having an option for 2 args var() better and I believe Shahrokh will prefer that (I'm emailing him about this PR). |
to be honest, i do not really see how |
What about |
wouldn't preventing it from being callable before a |
depends. (i also think that |
there's no 'upvote' on github so.. +1 vote for set at some point you may as well include a small c compiler or interpreter or something instead (or I suppose you could keep extending the expr 'language' to include control flow and local variables etc.) |
related to #2431
we can store values in variables as in [expr x = $f1]. But something like [expr var($s1) = $f2] doesn't work, the object doesn't create and we get a 'expr: syntax error'
since (all of the?) functions in
expr
resolve to a concrete value, to solve this problem, i'd propose another function that returns only a variable reference to the valueso in the case of
[expr function($s1) = $f2]
wherefunction
is only syntactically correct in its current position, if a variable matches$s1
it would internally resolve to: first[expr a = 2.5]
wherea
is the variable and2.5
is the value of$f2
, and thena
would be bound to that variable.the function implementation is identical to
ex_var
with the exception of variable binding, of course.i'm open to suggestions.