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

if-let behavior appears different in #1188 #1189

Closed
sogaiu opened this issue Jun 11, 2023 · 5 comments · Fixed by #1190
Closed

if-let behavior appears different in #1188 #1189

sogaiu opened this issue Jun 11, 2023 · 5 comments · Fixed by #1190

Comments

@sogaiu
Copy link
Contributor

sogaiu commented Jun 11, 2023

The following code used to not error for me:

(if-let [[l r] (peg/match "a" "b")]
  :a
  :b)

With 2c3ca29 I get:

$ janet
Janet 1.28.0-dev-2c3ca298 linux/x64/gcc - '(doc)' for help
repl:1:> (if-let [[l r] (peg/match "a" "b")]
repl:2:(>   :a
repl:3:(>   :b)
error: expected string, symbol, keyword, array, tuple, table, struct or buffer, got nil
  in _thunk [repl] (tailcall) on line 1, column 1

With 94722e5 I get:

$ ./build/janet
Janet 1.28.0-dev-94722e56 linux/x64/gcc - '(doc)' for help
repl:1:> (if-let [[l r] (peg/match "a" "b")]
repl:2:(>   :a
repl:3:(>   :b)
:b
@sogaiu
Copy link
Contributor Author

sogaiu commented Jun 11, 2023

Note that when-let (as it's implemented in terms of if-let) is also affected as well:

$ janet
Janet 1.28.0-dev-2c3ca298 linux/x64/gcc - '(doc)' for help
repl:1:> (when-let [[a b] nil] :a)
error: expected string, symbol, keyword, array, tuple, table, struct or buffer, got nil
  in _thunk [repl] (tailcall) on line 1, column 1

For comparison its older behavior was:

$ ./build/janet
Janet 1.28.0-dev-94722e56 linux/x64/gcc - '(doc)' for help
repl:1:> (when-let [[a b] nil] :a)
nil

@sogaiu
Copy link
Contributor Author

sogaiu commented Jun 11, 2023

I'm pretty sure I came to rely on the not-erroring behavior because it seemed more convenient. I didn't look into why it was working and I didn't check that this wasn't intended (at least I didn't look closely at various docstrings nor did I ask around).

I suppose if I'm alone in having gone this path then the good news is that there's only one person who needs to rewrite code :)

@primo-ppcg
Copy link
Contributor

primo-ppcg commented Jun 11, 2023

I suppose if I'm alone in having gone this path then the good news is that there's only one person who needs to rewrite code :)

(if-let [[a b] (possibly-nil-or-tuple)] ...)

Seems like a perfectly valid use case, at least to me. I'll make an amendment.

@zevv
Copy link
Contributor

zevv commented Jun 11, 2023

But this will mean the rules for not being to able to deconstruct a nil will be different from not being able to deconstruct something else?

(if-let [a b] (something-that-can-not-be-deconstructed-into-a-b-tuple) ...)

@primo-ppcg
Copy link
Contributor

But this will mean the rules for not being to able to deconstruct a nil will be different from not being able to deconstruct something else?

Yes, by definition really.

if-let
If any are false or nil, evaluate the fal form.

primo-ppcg added a commit to primo-ppcg/janet that referenced this issue Jun 11, 2023
primo-ppcg added a commit to primo-ppcg/janet that referenced this issue Jun 11, 2023
primo-ppcg added a commit to primo-ppcg/janet that referenced this issue Jun 11, 2023
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

Successfully merging a pull request may close this issue.

3 participants