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

make for, while, etc. return Nothing instead of () #28

Closed
StefanKarpinski opened this issue Jun 1, 2011 · 7 comments
Closed

make for, while, etc. return Nothing instead of () #28

StefanKarpinski opened this issue Jun 1, 2011 · 7 comments
Assignees

Comments

@StefanKarpinski
Copy link
Member

We discussed this once a long time ago and decided that it would be nice to have a Nothing object that prints as nothing. Then when entering code into the repl, one doesn't have to worry about putting an unseemly ; at the end of a for loop to suppress the annoying (). Also it would make some potential errors more sensible: if you try to do anything with the Nothing value it can throw a fairly specific error, whereas () is a perfectly legitimate value for many expressions to produce.

@ghost ghost assigned StefanKarpinski Jun 1, 2011
@JeffBezanson
Copy link
Member

BTW, not "if" since that returns the value of whatever branch executes.

@JeffBezanson
Copy link
Member

...unless of course no branch executes.
I see you assigned yourself so I'll just make some helpful comments. In the intermediate representation I use (null) (null_sym in C) for "no value" so the interpreter and compiler should return Nothing for this instead. Nothing should be defined in boot.j and handled in init.c and dump.c the same as the other stuff in jl_get_builtin_hooks(). Then replace jl_null with jl_nothing where appropriate in the C code --- this is tricky, as some cases actually need to be 0-tuples. Replacing the cases in j/ should be fairly easy.

@StefanKarpinski
Copy link
Member Author

Excellent. Thanks for the tips. Will attempt this.

On Jun 2, 2011, at 6:32 PM, JeffBezansonreply@reply.github.com wrote:

...unless of course no branch executes.
I see you assigned yourself so I'll just make some helpful comments. In the intermediate representation I use (null) (null_sym in C) for "no value" so the interpreter and compiler should return Nothing for this instead. Nothing should be defined in boot.j and handled in init.c and dump.c the same as the other stuff in jl_get_builtin_hooks(). Then replace jl_null with jl_nothing where appropriate in the C code --- this is tricky, as some cases actually need to be 0-tuples. Replacing the cases in j/ should be fairly easy.

Reply to this email directly or view it on GitHub:
#28 (comment)

@StefanKarpinski
Copy link
Member Author

I'm getting errors like this:

type error: new_struct_type: expected Function, got NothingType /Users/stefan/projects/julia/j/sparse.j:2 /Users/stefan/projects/julia/j/sysimg.j:58

which I think comes from this line:

#3  0x00000001000290c9 in jl_f_new_struct_type (env=0x0, args=0x7fff5fbfc478, nargs=4) at builtins.c:993
992     if (args[3] != (jl_value_t*)jl_null)
993         JL_TYPECHK(new_struct_type, function, args[3]);
(gdb) p args[3] == jl_null   
$6 = 0
(gdb) p args[3] == jl_nothing
$7 = 1

So jl_f_new_struct_type is getting jl_nothing when it should be getting jl_null. I think this is a matter of the codegen/interpreter turning null_sym into jl_nothing where it should be yielding jl_null but I'm not sure what to do about it. Presumably the parser should distinguish between () and Nothing.

@JeffBezanson
Copy link
Member

In this case the frontend is passing (null) to new_struct_type just as a flag to indicate nothing is there. Change jl_f_new_struct_type to expect jl_nothing instead.

@JeffBezanson
Copy link
Member

If you want you can send me a list of occurrences of jl_null you're not sure about and I can help.

@StefanKarpinski
Copy link
Member Author

Closed by 20e911d.

cmcaine pushed a commit to cmcaine/julia that referenced this issue Sep 24, 2020
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Oct 11, 2021
KristofferC pushed a commit that referenced this issue Aug 25, 2023
…1047)

Stdlib: NetworkOptions
URL: https://github.com/JuliaLang/NetworkOptions.jl.git
Stdlib branch: master
Julia branch: master
Old commit: f7bbeb6
New commit: 976e51a
Julia version: 1.11.0-DEV
NetworkOptions version: 1.2.0 (Does not match)
Bump invoked by: @DilumAluthge
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/NetworkOptions.jl@f7bbeb6...976e51a

```
$ git log --oneline f7bbeb6..976e51a
976e51a Use human-readable title in the docs (#30)
895aee9 Update ssh-rsa key for github.com (#29)
db83efd fix an issue found by JET (#28)
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Keno pushed a commit that referenced this issue Oct 9, 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

No branches or pull requests

2 participants