News for hackers. Stuff that matters.
Re:No Stinking Loops by kelseyfrog on Saturday December 16, 2023 @01:44PM (#38666657)
It looks K-centric. The K language provides constructs like each, over, and scan to perform what would be looping behavior in other languages.

Having written Scala myself at one point, the thought of a loop-less language crossed my mind. It's amazing what you can accomplish with foldLeft and recursion schemes.

Re:No Stinking Loops by cortesoft on Saturday December 16, 2023 @01:50PM (#38666715)
Aren’t those things just convenience wrappers around loops? I don’t understand the fundamental difference.
Re:No Stinking Loops by kibwen on Saturday December 16, 2023 @01:56PM (#38666766)
They're loops with stronger semantics (in other words, they're more restrictive (in other words, they're easier to reason about)), in the same way that loops themselves are `goto` with stronger semantics.
Re:No Stinking Loops by kelseyfrog on Saturday December 16, 2023 @02:47PM (#38667121)
> they're more restrictive (in other words, they're easier to reason about))

That's a great point. Often in my programming career, I've used the rule of least power[1]. In the looping/flow control ladder, I'd list descending

* JMP/GOTO

* for/while

* map/filter/reduce

If a problem only needs a map, using a for introduces needless complexity(ie: state). Personally, I think we have a pedagogical problem in that we teach people loops first and people confuse what they've been taught first with what is a reasonable choice[2].

For completeness, recursion has it's own ladder

* PUSH,POP,JMP

* function call

* recursion schemes[3]

Side note: recursion schemes have an enormous hurdle to adoption in that mathematicians got there first and the naming are so off putting that no one will take you serious if you bring up even simple schemes like anamorphism and catamorphism. Folks would rather accept a FactoryFactoryFactory over a futumorphism.

1. https://en.wikipedia.org/wiki/Rule_of_least_power

2. The other side of this coin is, "Why would they teach me a bad way of doing something?"

3. https://github.com/passy/awesome-recursion-schemes

Re:No Stinking Loops by accrual on Saturday December 16, 2023 @05:58PM (#38668577)
Viewing loops as a stronger GOTO is a really interesting perspective which makes sense to me, thanks for the insight.
Re:No Stinking Loops by otikik on Saturday December 16, 2023 @07:18PM (#38669145)
I see them as a restricted (so, less powerful than a goto). That’s why they are better. Perhaps that’s what you meant when you said “stronger”
Re:No Stinking Loops by dan-robertson on Saturday December 16, 2023 @01:58PM (#38666779)
Aren’t loops just wrappers around goto and if statements?

The claim is that by expressing programs in terms of these array primitives, you (a) can have those primitives be super optimised and (b) better see what the program is actually about without worrying too much about eg what names to give all the loop counters, all the other intermediate state associated with iteration, etc.

Re:No Stinking Loops by erik_seaberg on Saturday December 16, 2023 @11:04PM (#38670227)
Most platforms make some kind of loop into a primitive, but in Common Lisp

  (dotimes (i 10)
    (print i))
is just a predefined macro that might expand into primitives like

  (BLOCK NIL
    (LET ((I 0))
      (TAGBODY
        #:LOOP-2867
        (IF (>= I 10)
          (GO #:END-2868))
        (PRINT I)
        (PSETQ I (1+ I))
        (GO #:LOOP-2867)
        #:END-2868
        (RETURN-FROM NIL (PROGN NIL)))))
Re:No Stinking Loops by d0mine on Saturday December 16, 2023 @02:31PM (#38667023)
Loops themselves can be considered just convenient wrappers around goto. The point is to restrict the variety (structured programming) and make spaghetti unreadable code less likely.

Using higher-order functions instead of loops is similar e.g. loops:

    # input_ =  "1,2,3"
    numbers = (int(d) for d in input_.split(","))
    product = 1
    for n in numbers:
        product *= n
can be replaced:

    numbers = map(int, input_.split(","))
    product  = reduce(mul, numbers, 1)
Re:No Stinking Loops by ssivark on Saturday December 16, 2023 @02:18PM (#38666933)
Loops (Eg: in C) are a much “wilder” construct — something special could happen for i=17 or successive iterations might overwrite values, etc. more restrictive “tamer” versions help programmers & computers reason about the code.
Re:No Stinking Loops by ksherlock on Saturday December 16, 2023 @02:02PM (#38666818)
Sure, and C is a convenience wrapper around assembly and assembly is a convenience wrapper around toggling octal codes on your front panel and punching in octal code is a convenience wrapper around rewiring vacuum tubes and relays and that's a convenience wrapper around mechanical cogs and that's a convenience wrapper around an abacus.

But it's a different paradigm than procedural programming and embracing it might lead to a different mind set.

Re:No Stinking Loops by lamerose on Saturday December 16, 2023 @02:15PM (#38666913)
Lol. IMO the difference between an C and Assembly (as between vacuum tubes and the abacus) is really a difference in power, since it allows the same program to be implemented on different architechtures. It's only fair to start calling things convenience wrappers once you get past C. And often enough, an abstraction aimed at convenience leads to a reduction in expressive power.
Re:No Stinking Loops by dwb on Saturday December 16, 2023 @01:58PM (#38666777)
When loopless constructs are a design principle of a language, they become much more than just a convenience wrapper.
Re:No Stinking Loops by epanchin on Saturday December 16, 2023 @05:37PM (#38668424)
each is a necessary evil of K. It can often be avoided by more thoughtful use of vectors.
Re:No Stinking Loops by fifilura on Saturday December 16, 2023 @02:12PM (#38666876)
I would claim that SQL is the ubiquitous loop-less language.

Once you get into it, you start realizing what manipulating data is all about. And most of what you need can be expressed without for loops. And then the step from SQL to Scala is not long.

For me imperative languages are like Lego. SQL is like origami. You fold yourself to the solution.

That said, K is obviously one step further in that analogy.

Re:No Stinking Loops by the_gipsy on Saturday December 16, 2023 @01:45PM (#38666670)
Elm doesn't have loops, just fold/map.
Re:No Stinking Loops by lamerose on Saturday December 16, 2023 @02:20PM (#38666942)
Elm can do iterative recursion, which is a thinly disguised loop without side effects.
Re:No Stinking Loops by the_gipsy on Wednesday December 20, 2023 @03:09AM (#38706437)
I googled "iterative recursion " and couldn't find a definition. So is it judt iteration? And then, what languages don't have iteration?
Re:No Stinking Loops by epanchin on Saturday December 16, 2023 @05:29PM (#38668367)
Primarily K focuses on applying functions to vectors. If using “each” can be avoided, it is.

It’s a wonderful language to work with.