4 ms·
> I'm not sure about the "learn it as a first language" bit. I think this is very subjective. Our minds have been "poisoned" - or rather trained over years - i
by qayxc 4y ago
> I'm not sure about the "learn it as a first language" bit.
I think this is very subjective. Our minds have been "poisoned" - or rather trained over years - into a very specific way of thinking about expressions like in the example.
A first programming language, however, assumes that the learner hasn't been preconditioned in any way into a certain paradigm. So just keeping the two rules in mind that 1) evaluation is strictly from left to right and 2) an expression evaluates to a sequence of zero or more values immediately makes sense of the example.
Unfortunately it's incredibly hard to "reset" your mind into a state that doesn't know about variable assignments and thinking of variables as singular slots as is the case in Haskell and most other programming languages.
That's why "intuition" is a very subjective thing - your intuition changes with knowledge and experience and both are hard to suppress.
- davidw 4y agoI get that to some degree, but that code doesn't look like something most people are exposed to, whereas 'x = 10' or something that says 'foreach' seems like it'd make sense with a minimum of explanation to a lot of people. x:=(1|2); y:=(7|8); (x,y) Doesn't look like any math I'm familiar with.
- jbritton 4y agoYou can think of the choice ( | ) as a generator function. X generates 1 then 2. Y generates 7 then 8. For x in [1,2]: For y in [7,8]: yield (x, y)
- deleted 4y ago[deleted]
- psyklic 4y agoYou could also write the example as a list comprehension, which essentially mimics set-builder notation in math, i.e. "The set of all pairs such that ..." [(x, y) for x in [1, 2] for y in [7, 8]] // Python (list comprehension) {(x, y) | x \in {1, 2}, y \in {7, 8}} // math (set-builder notation)
- davidw 4y agoSee, the Python code has some hints as to what's going on. If you know that x is a variable, 'for x in' spells it out to some degree. Maybe you don't nail the exact functionality just from looking, but it feels more accessible.
- yazzku 4y agoCartesian product.
- baby 4y ago+1 to this I remember struggling to understand the x = 7 syntax for storing a value in x. My young self was like “so if x is equal to 7, how come we can write x is equal to 8 later? That doesn’t make sense”
- eyelidlessness 4y agoA cool thing about this in Erlang (which I think is the same in Prolog) is that the = operator works almost exactly how you would have expected: it binds the value but then it asserts the binding’s equality. So once you’ve established x = 7, x = 8 is actually an error! Because you’re right, it doesn’t make sense that at one point x = 7 and later the same x = 8!
- baby 4y agoThat's what I did in my own language[1], no shadowing allowed. [1]: https://github.com/mimoo/noname https://github.com/mimoo/noname