Skip to content
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

Popping into the parent environment? #17

Open
trans opened this issue Jul 30, 2024 · 1 comment
Open

Popping into the parent environment? #17

trans opened this issue Jul 30, 2024 · 1 comment

Comments

@trans
Copy link

trans commented Jul 30, 2024

I thought it would be nice if we could put the name of function first when defining it, so I wrote this:

($t $w ^t ^w pop) $.

For example:

(  
  ($t $w ^t ^w pop) $.

  'foo ( $x ^x print ) .
  12 foo
)

This would print 12, but instead it errors saying it Failed to find in key='foo' in environment. But it almost works, if I write instead:

(  
  ($t $w ^t ^w pop 12 foo) $.
  'foo ( $x ^x print ) .
)

It will print 12, since foo gets defined in that first sub-environment. But obviously, I want to push the definition up into in the parent environment.

Is there a way to do this that I am missing?

@ursi
Copy link

ursi commented Jul 31, 2024

You can't pop in a closure because it only defines the variable in the closure. The simplest way to define something with the name first is

'name
  <value>
  swap pop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants