ref keyword #38

Merged
defunkt merged 1 commits from ref-keyword into main 2025-11-09 00:03:45 +00:00
Owner

(It's not really a keyword)

We might want to discuss this, as there are a few options. But this adds a ref function that lets you get a reference to a function without calling it.

It's kinda like ruby's method(:fn_name), but just ref fn-name instead.

The reason we have this is because just writing fn-name means you'll call the function, ex:

random-number = math.random # 0.9136444434009429

but you might want to do:

rng = ref math.random    # <native>
random-number = rng    # 0.2417472671625721

We could also do it with syntax, but I think there are reasons to just make it a builtin:

# using an @prefix, but we might want to keep that for words or save for decorators?
rng = @math.random

# using a &prefix, but maybe we want to save & for the background job symbol later?
rng = &math.random

Builds on #37 as it addresses a problem it introduces with no-arg function calls.

(It's not really a keyword) We might want to discuss this, as there are a few options. But this adds a `ref` function that lets you get a reference to a function without calling it. It's kinda like ruby's `method(:fn_name)`, but just `ref fn-name` instead. The reason we have this is because just writing `fn-name` means you'll call the function, ex: ``` random-number = math.random # 0.9136444434009429 ``` but you might want to do: ``` rng = ref math.random # <native> random-number = rng # 0.2417472671625721 ``` We could also do it with syntax, but I think there are reasons to just make it a builtin: ``` # using an @prefix, but we might want to keep that for words or save for decorators? rng = @math.random # using a &prefix, but maybe we want to save & for the background job symbol later? rng = &math.random ``` Builds on #37 as it addresses a problem it introduces with no-arg function calls.
defunkt added 2 commits 2025-11-08 09:00:24 +00:00
defunkt force-pushed ref-keyword from 88434a932a to 4c3f7a8bfc 2025-11-09 00:03:35 +00:00 Compare
defunkt merged commit 012b8c8cf1 into main 2025-11-09 00:03:45 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: probablycorey/shrimp#38
No description provided.