this post was submitted on 29 May 2025
-4 points (47.1% liked)

Funny Comics

143 readers
38 users here now

A space for sharing funny comics and cartoons.

founded 1 month ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] glimse@lemmy.world 2 points 3 days ago (1 children)

I'm not an actual programmer but I've dabbled in enough languages to be able to get a gist of what basic code does - or at the very least, quickly understand the syntax the language uses.

LISP, however...what the fuck is going on here?

It's confusing because lisp isn't a language, it's a text syntax for trees. You don't write lisp code, you directly write the abstract syntax tree that most language are converted into.

Various flavors of lisp offer a selection of macros and functions to create a useful programming system. Thats how you get Racket (more functional style), Common Lisp (with object system for more OOP style), or Clojure (with other kinds of brackets and free Java built in). Plus the hundreds of others.

Consider something like a loop or an if-else ladder. In a c-like language:

if (condition == test) { call_function(x,2,"aaaa"); }
else if (condition < test) { print("woah"); }
else { throw new Error(); }

In a lisp-like language:

(if (eq condition test) (call-function x 2 "aaaa")
(if (lt condition test) (print "woah")
(throw (Error new))))

In lisp, "if" is a function that takes 3 params: the condition, the do-if-true block, and the do-if-false block. In c-like, "if" is an expresssion in the language, with a similar structure. Notice how the lisp structure is fully nested. I left off a pair of optional curly braces on the second line of the c version, but technically there's no "else if" construct (well, there is in some languages, but bear with me) but rather an "else {}" block which contains a second if-else expression. The lisp version makes this nesting explicit.

Other stuff like prefix notation for everything is optional (Clojure has infix operators and other kinds of braces) or you just get used to it (like open parens going in front of function names instead of after them.)