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

The null and undefined should be added to false values #330

Closed
3 tasks done
jcubic opened this issue Mar 5, 2024 · 7 comments
Closed
3 tasks done

The null and undefined should be added to false values #330

jcubic opened this issue Mar 5, 2024 · 7 comments

Comments

@jcubic
Copy link
Collaborator

jcubic commented Mar 5, 2024

Accord to Scheme spec #f should be the only falsy value, but LIPS use two constants from JavaScript : null and udefined. I was caught multiple times when using String::match when I didn't use: (not (null? x)).

This will simplify user code if both null and undefined are false values. So the old behavior will be restored.

It's kind of silly that null and undefined are true.

It's intuitive to write:

(if (str.match #/foo/)
    (display "it's foo"))
  • Update if
  • Update and
  • Update or
@lassik
Copy link

lassik commented Mar 5, 2024

Several Scheme implementations have an "unspecifed" or "void" value. It is returned by procedures where RnRS says the return value is unspecifed. JS undefined would be a good fit for this purpose.

The unspecified/void value is not considered false. This is intentional.

Survey

@lassik
Copy link

lassik commented Mar 5, 2024

RnRS has no clear equivalent to JS null. Perhaps look at how Kawa handles Java's null.

@jcubic
Copy link
Collaborator Author

jcubic commented Mar 6, 2024

Thanks will check.

@jcubic
Copy link
Collaborator Author

jcubic commented Mar 6, 2024

Maybe I should add warning when if, and, or gets null or undefined as argument. Scheme forces to use #f as the only false value, but if users use if with null this is probably a mistake on his end. I can make a flag to disable the warnings. @lassik what you think about something like this.

@jcubic
Copy link
Collaborator Author

jcubic commented Mar 6, 2024

Kawa have #!null and #!void constants:

(unless #!null (display "x\n"))
;; ==> x
(when #!void (display "x\n"))
;; ==> x

so null is false in Kawa.

@lassik
Copy link

lassik commented Mar 7, 2024

Maybe I should add warning when if, and, or gets null or undefined as argument.

That might be a good idea.

null is false in Kawa.

That probably makes sense, because null has a similar purpose in Java (and JavaScript) as #f has in Scheme. Both null and #f are used to indicate "it would be meaningful to have an object here, but we don't have one now". This is similar to nil in Lisp. (As you say, Scheme does not use nil.)

In Scheme, undefined and void indicate "it would be meaningless to have an object here".

@lassik
Copy link

lassik commented Mar 7, 2024

For example, assoc returns #f to indicate "I tried to find an object, but I didn't find one".

But write returns unspecified because it would be meaningless to return anything.

jcubic added a commit that referenced this issue Mar 7, 2024
jcubic added a commit that referenced this issue Mar 7, 2024
@jcubic jcubic closed this as completed Mar 7, 2024
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