Passing null to a function triggers default value #41

Merged
defunkt merged 1 commits from null-triggers-default-values into main 2025-11-09 00:02:27 +00:00
Owner

⚠️ CONTROVERSIAL ⚠️

password = do length=20: blah blah end

password 50 #=> passes 50
password null #=> sets to 20

In most other languages this will pass in a null directly, but I think we need some way to say "just use the default" because we'll be parsing stuff from the command line.

Just doing:

password = do length=20:
  length = if length == null: 20 end
  # ...
end

Kinda defaults the purpose!

Here's how I'm trying to use it in my password script, without it:

password = do n=22 no-symbols=true not-spaced=true:
  # blah
end

num = args | list.slice 2 | list.reject do x: x | str.starts-with? ! end | list.first
if not num: num = 22 end

password num no-symbols=(args | contains? !symbols) not-spaced=(args | contains? !spaced) | echo⏎               

And with it:

password = do n=22 no-symbols=true not-spaced=true:
  # blah
end

num = args | list.slice 2 | list.reject do x: x | str.starts-with? ! end | list.first
password num no-symbols=(args | contains? !symbols) not-spaced=(args | contains? !spaced) | echo⏎               
⚠️ CONTROVERSIAL ⚠️ ``` password = do length=20: blah blah end password 50 #=> passes 50 password null #=> sets to 20 ``` In most other languages this will pass in a `null` directly, but I think we need some way to say "just use the default" because we'll be parsing stuff from the command line. Just doing: ``` password = do length=20: length = if length == null: 20 end # ... end ``` Kinda defaults the purpose! Here's how I'm trying to use it in my password script, without it: ``` password = do n=22 no-symbols=true not-spaced=true: # blah end num = args | list.slice 2 | list.reject do x: x | str.starts-with? ! end | list.first if not num: num = 22 end password num no-symbols=(args | contains? !symbols) not-spaced=(args | contains? !spaced) | echo⏎ ``` And with it: ``` password = do n=22 no-symbols=true not-spaced=true: # blah end num = args | list.slice 2 | list.reject do x: x | str.starts-with? ! end | list.first password num no-symbols=(args | contains? !symbols) not-spaced=(args | contains? !spaced) | echo⏎ ```
defunkt added 1 commit 2025-11-08 18:58:00 +00:00
defunkt merged commit fe6f54b402 into main 2025-11-09 00:02:27 +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#41
No description provided.