← Back to context

Comment by anthk

20 hours ago

I tried some ML language once, it's difficult even to write a basic factorial example, which in Scheme I could do it iteratively and recursively with ease.

Either with S9 Scheme for quick fun (it has Unix sockets and ncurses :D ) or Chicken Scheme for completeneless (R5RS/R7RS-small + modules), I always have fun with both.

Oh, and well, Forth, too, but more like a puzzle (altough it shines to teach you that you can do a lot with a fixed point). Hint: write helpers for rationals -a/b where a is an integer and b a non-zero integer- and complex numbers by placing two items in the stack for each case (for rat helpers you need four (a/b [+-*/] c/d) .

You can have a look at qcomplex.tcl (either online or installed) as an example on how can it work even under JimTCL itself by just sourcing that file. Magic, complex numbers under jimsh thanks to the algebraic properties. So, you can implement the same for yourself in some Forths, even under EForth for Muxleq. Useless? It depends, under an ESP32 it can be damn fast, faster than Micropython.

I don't see how:

Racket:

  > (define (fact n)
      (if (= n 1)
          1
          (* n (fact (- n 1)))))
  > (fact 6)
  720

OCaml:

  # let rec fact = function
      | 1 -> 1
      | n when n > 1 -> n * (fact (n - 1))
    in fact 6;;
  - : int = 720

  • Whenever someone complains about not being able to use a slightly different syntax, I assume they just don't have any neuroplasticity anymore.

    • I think syntax matches with our brains or not. I think anyone is capable of learning any syntax. The question is whether they want to. At some level, programming is art.

From my limited SMLNJ experience I think for something as simple as factorial, it is nearly the same. Both have TCO, recursion, inner functions, pattern matching and those good things. You can structure the code the same way.

Even as simple as

  fac 1 = 1
  fac n = n * (fac (n - 1))

which is a working Haskell implementation?

I mean, in Scheme it is longer to write. I enjoy Lisps and use Emacs for everything, but Haskell can be as terse, or even more terse. (Which is not always a good thing.)

  • I think in terms of token count it comes out to about the same; and Lisp admits fewer kinds of tokens.

> I tried some ML language once, it's difficult even to write a basic factorial example

What do you mean? It's one of the first things taught in any tutorial for the ML family or Haskell.