News for hackers. Stuff that matters.
Re:Little is a statically typed, C-like scripting language by luckydude on Saturday February 20, 2021 @11:44AM (#26205493)
You get undef, that's part of the reason we added an undef concept (it's a value that isn't a value, though if you treat it like an int I believe it is zero, like a string and you get "").
Re:Little is a statically typed, C-like scripting language by CyberDildonics on Saturday February 20, 2021 @03:31PM (#26207655)
I think that is a giant design mistake since you are pushing the discovery of an error to some place else in the program, potentially very far from where the error occurred.
Re:Little is a statically typed, C-like scripting language by luckydude on Saturday February 20, 2021 @04:40PM (#26208232)
Without providing an example of how to do it better, I'm not sure I see your point. Yeah, I see the problem you point out.

Consider

char *p = 0;

some complicated code that should have set p but didn't...

char c = *p; // SEGV

So do you have a way to push that error all the way back to wherever you think it should be pushed?

Re:Little is a statically typed, C-like scripting language by CyberDildonics on Saturday February 20, 2021 @05:05PM (#26208421)
The person you replied to asked what the behavior was when you access an offset of an array that doesn't exist and you are giving me an example of dereferencing a null pointer.

The array access should error out on the line that it happens.

The dereference could print a line of the last assignment, but this isn't what was being talked about.

Re:Little is a statically typed, C-like scripting language by luckydude on Saturday February 20, 2021 @05:13PM (#26208483)
I don't see the array access as any different than a null pointer dereference, in both cases you are asking for something that isn't there.

In Tcl, stuff just gets auto expanded on assignment and returns "" (I think) on dereference. We chose to return undef. I'm not sure what the problem is.

Re:Little is a statically typed, C-like scripting language by CyberDildonics on Saturday February 20, 2021 @05:29PM (#26208578)
I explained the problem already (the error does not show up where it actually happens).

I also explained a huge difference between the two already (you know how large an array is and can detect an out of bounds access when it happens).

Re:Little is a statically typed, C-like scripting language by luckydude on Saturday February 20, 2021 @06:05PM (#26208895)
You seem bound and determined to not hear that tcl auto expands arrays as needed. There are no bounds. So there is no error to catch.

We just thought it would be clever to return undef if you were out of bounds, which tcl code would see as "" which is what you'd get in tcl. But Little code could actually tell you are past the end.

In my mind, which many have argued isn't the best, it's a reasonable design.

You keep trying to push backwards to a design point where arrays are fixed in size at declaration and that is not how tcl (or Little) works.

Re:Little is a statically typed, C-like scripting language by zimpenfish on Saturday February 20, 2021 @07:25PM (#26209537)
> There are no bounds. > clever to return undef if you were out of bounds

You can see how this is getting confusing.

> So there is no error to catch.

Thing is, you're already catching the error because "Little code could actually tell you are past the end" and "return undef if you were out of bounds" - you're just smooshing the error under the carpet into an `undef` return rather than bombing out with an OOB error (which is what I think GP was actually after.)

(If Little returns `undef` for OOB and `""` for in-bounds-not-set, you can detect the OOB access error in your own code but that hasn't been made clear, I don't think?)

Re:Little is a statically typed, C-like scripting language by luckydude on Saturday February 20, 2021 @08:35PM (#26209997)
Little returns undef for OOB and for in bounds not set. Tcl returns "" for both.

The thing that GP was asking for, an OOB error, is not a thing in a language where there are no bounds.

Re:Little is a statically typed, C-like scripting language by IshKebab on Saturday February 20, 2021 @11:59AM (#26205657)
So there's `undef` and `null`? I wonder if there's a popular language that made the same mistake you could have learnt from :-P
Re:Little is a statically typed, C-like scripting language by luckydude on Saturday February 20, 2021 @12:04PM (#26205714)
There is no null, only undef. It's not a value, there is no value that means undef. We implemented by stealing the high order bit from the reference counter that tcl uses for garbage collection. If it is set, the variable undefined, if it isn't, it's a normal variable.

I thought that was clever given that tcl's reference counter was signed and it only uses positive values. So we made it unsigned and got the bit for free.

Re:Little is a statically typed, C-like scripting language by skybrian on Saturday February 20, 2021 @01:15PM (#26206391)
What happens if you call a Tcl function with an undef argument? Is this running Tcl code on a slightly different runtime, or do they interop in some other way?
Re:Little is a statically typed, C-like scripting language by luckydude on Saturday February 20, 2021 @04:44PM (#26208261)
In Tcl, everything is a string. The string rep of undef is "" so Tcl gets "" but doesn't know that it is undef.

So yeah, there is some sloppiness there. Tcl tends to use "" as sort of a null or undef so lots of stuff just works but no promises on that.

This is sloppy simply because the Tcl die hards (are there any left?) refused to see the value of undef, a value for a variable that said there is no value. We used it all over the place, there clearly is value. They didn't see that, Little never got pushed back into the Tcl source base so Tcl never thought about undef.

It is what it is, we live in an imperfect world. I tried.