News for hackers. Stuff that matters.
Re:Ask HN: 30y After 'On Lisp', PAIP etc., Is Lisp Still "Be... by iLemming on Saturday June 08, 2024 @02:37AM (#40615731)
Ah... now I see what you meant. Indeed. + is an operator in langs like Javascript and C++ - a built-in, rigid syntax construct. You can't redefine it, you can't extend it, you can only use it for addition and string concatenation. You can't even extend it in JS to let's say, merge two objects together.

Lisp doesn’t even have "operators" — everything is a function. Gosh, the more you learn about Lisp, the more it feels like we went backwards. We tried to simplify programming, only to find ourselves buried under layers of complications. Just think about how many times we've reinvented state management for React alone: Redux, MobX, Recoil, Zustand, Jotai, Effector, XState, Overmind, Hookstate, Easy Peasy, Rematch. And that's not even a comprehensive list. What's funny is that some of these are "improved" versions of previous "improvements". Each time we try "improving" the previous "improvement", it seems we continually need to reinvent another layer of "improvements". Dafuk are we doing?

Re:Ask HN: 30y After 'On Lisp', PAIP etc., Is Lisp Still "Be... by lispm on Saturday June 08, 2024 @07:05AM (#40616786)
> Lisp doesn’t even have "operators" — everything is a function. Gosh, the more you learn about Lisp, the more it feels like we went backwards.

Don't learn wrong things. Lisp has operators and no, not everything is a function. LET for example is not a function. It is a built-in special operator in Common Lisp. Similar in other Lisp dialects. Scheme R7RS documents "let" as syntax: https://standards.scheme.org/corrected-r7rs/r7rs-Z-H-6.html#... with a "named let" as a variant: https://standards.scheme.org/corrected-r7rs/r7rs-Z-H-6.html#...

In Emacs Lisp: https://www.gnu.org/software/emacs/manual/html_node/eintr/le...

"The let expression is a special form in Lisp..."

Also: limiting the redefinition of standard operators is not backwards, it's useful, to prevent to crash a Lisp, since in Lisp function names are often late bound. -> changing a core function will have immediate effect on all code using that.

Macros are also not "function". Macros are operators which expand source code to new source code.

Lisp typically has these operator types:

  * functions, which are operators which get called with evaluated arguments
  * macros, which are operators, which get called with source code and which return new source code
  * special operators (QUOTE, LET, DEFUN, SETQ, IF, ...), which are typically hard-wired in the implementation with both syntax and semantics. Scheme has a set of those, too.
 
Additionally one my see fexprs, which are operators, which are called with source code. Then in some Lisps some functions lazy evaluate their arguments.

The glossary of Common Lisp explains "operator": https://www.lispworks.com/documentation/HyperSpec/Body/26_gl...

  operator n.
  1. a function, macro, or special operator.
  2. a symbol that names such a function, macro, or special operator.
  3. (in a function special form) the cadr of the function special form, which might be either an operator[2] or a lambda expression.
  4. (of a compound form) the car of the compound form, which might be either an operator[2] or a lambda expression, and which is never (setf symbol).
> You can't redefine it

In standard Common Lisp it is UNDEFINED what happens when one redefines a standard operator of Common Lisp. Typical implementations will signal an error (which often provides a restart). Typical implementations will also extend this to other protected packages, such that the user can't accidentally replace an operator and the Lisp system may crash.

Re:Ask HN: 30y After 'On Lisp', PAIP etc., Is Lisp Still "Be... by 6510 on Saturday June 08, 2024 @12:40PM (#40618745)
I started out writing machine code. With each "improvement" we lost flexibility and I didn't need any of it but they are all useful experiments and lots of things objectively improved. Imho software is for fooling around. We need it because we don't exactly know what we need or how to make it. When the needs are exactly defined we can bake thing into hardware. At that point all flexibility is gone.
Re:Ask HN: 30y After 'On Lisp', PAIP etc., Is Lisp Still "Be... by kazinator on Saturday June 08, 2024 @10:01PM (#40621484)
The syntax of + and - is rigid in C++, but functions can be written to extend it. This is not new; you are making claims that were not true in the first ISO C++ in 1998, or its predecessors revisions going quite far before that.

When a is a class type (and more recently this is now supported for enumerations also) then the surface syntax a + b means the same thing as a.operator+(b): invoking the operator + member function of a with argument b.

Re:Ask HN: 30y After 'On Lisp', PAIP etc., Is Lisp Still "Be... by Turing_Machine on Saturday June 08, 2024 @11:41PM (#40621851)
> functions can be written to extend it.

Unless I'm mistaken (which I may well be), you can't do that at runtime, only at compile time.

Re:Ask HN: 30y After 'On Lisp', PAIP etc., Is Lisp Still "Be... by kazinator on Monday June 10, 2024 @09:15PM (#40641208)
I replied to this not knowing exactly where the goalposts are.

Indeed, in C++, our a + b expression is statically analyzed to be working with specific types; the declared types of a and b. When that code is compiled, it will work with no other types.

However, if we anticipate that kind of extension, we can have a be a reference to some numeric_base class where operator + is a virtual function.

With some help from a bit of platform specific coding, we can have dynamically loaded modules which can provide new classes derived from numeric_base that ca be passed to existing code in the program which uses + on numeric_base.