this post was submitted on 13 Oct 2025
21 points (100.0% liked)

programming

276 readers
1 users here now

  1. Post about programming, interesting repos, learning to program, etc. Let's try to keep free software posts in the c/libre comm unless the post is about the programming/is to the repo.

  2. Do not doxx yourself by posting a repo that is yours and in any way leads to your personally identifying information. Use reports if necessary to alert mods to a potential doxxing.

  3. Be kind, keep struggle sessions focused on the topic of programming.

founded 2 years ago
MODERATORS
 

I get dizzy looking at C-like languages, they just feel incredibly hard to follow compared to an S-expression.

Everything this just so verbose and there's so much negative space between the lines. To be fair, this course is making us program using Java so maybe it has to do more with that.

you are viewing a single comment's thread
view the rest of the comments
[–] hello_hello@hexbear.net 2 points 1 week ago* (last edited 1 week ago) (1 children)

Jupyter notebook is not the same sort of repl that I'm referring to, its more accurately a literate programming app. REPL is when you load your entire program and then are able to introspect everything while it's running and make changes. It's kind of like having a debugger that you use in tandem with writing new code.

with regards to metaprogramming, have you taken a look at defining arbitrary syntax via Rust macros?

They took inspiration from lisp, but yes rust has macros but they're also hard to understand just like in Lisp if you don't understand them.

How readable do you find Lisp in codebases with thousands of lines of code?

Reading/understanding Lisp codebases is actually easier imo because you can load into a REPL and interactively study each section of the codebase.

I would not be able to tell what n was supposed to be, for example.

This is just a comment about liking static typing and there exists lisp dialects that are statically typed. I've omitted the Docstring but usually that would tell you what the parameters are.

Also like in non statically typed languages, you can infer that n is a number type because it's being used in procedures like '1-' which are for numbers.

For example, just remove all the paranthesis from the lisp snippet and see if you cant get the basic structure.

and building a string with HTML code in C-likes. Though, I dislike both approaches, and prefer templates, due to the fact that the environment can assist with HTML syntax that way.

I've been trying to say that lisp can create these templates automatically just by having things like SXML. I don't understand what you mean by "building a string with HTML code"

You can have a iterative loop inside SXML and it follows the same rules as the rest of your lisp code. You have to build a DSL in C-likes.

[–] Tomorrow_Farewell@hexbear.net 1 points 1 week ago (1 children)

REPL is when you load your entire program and then are able to introspect everything while it's running and make changes. It's kind of like having a debugger that you use in tandem with writing new code.

As in, LISP programs are commonly made to run in parallel with their REPL interfaces? I was under the impression that REPL usually requires for a program to finish executing prior commands.

They took inspiration from lisp

Apologies, I have tried looking this up, but I have been unable to find anything that would support this claim. Would you mind directing me to a source?

This is just a comment about liking static typing and there exists lisp dialects that are statically typed. I've omitted the Docstring but usually that would tell you what the parameters are.

It's not just static typing. In an expression like (a b c) the a seems to be able to be a function call, or a variable, and I do not see a way to determine that at a glance, compared to something like a(b, c) or [a, b, c].
Also, do docstrings enforce the types, or are they just comments?

Also like in non statically typed languages, you can infer that n is a number type because it's being used in procedures like '1-' which are for numbers.

Sure, but that is still more troublesome than type enforcement, and it's better for relevant bugs to be caught at the stage of development, instead of being discovered in production.

For example, just remove all the paranthesis from the lisp snippet and see if you cant get the basic structure.

That would make things even worse, I would argue. Comparing expressions (a b ((c d) e)) and a b c d e, the former actually informs me of the structure at least somewhat.
Also, on the note of parentheses, I would much prefer for functions to be called like f(x), rather than (f x). A factor that contributes to that is the fact that, with the former syntax, I can tell that that is a function call, and not just two items of some types in a list.

I've been trying to say that lisp can create these templates automatically just by having things like SXML. I don't understand what you mean by "building a string with HTML code"

Not sure how I can rephrase it, but what I have been talking about is composing HTML code the way one would be composing any sort of string, potentially with some additional structures with their methods for manipulating their contents and/or transforming them into the resulting code.

You can have a iterative loop inside SXML and it follows the same rules as the rest of your lisp code. You have to build a DSL in C-likes.

Why is running a similar loop over the contents of a structure in a C-like language not enough in this context?

[–] hello_hello@hexbear.net 1 points 1 week ago* (last edited 1 week ago) (1 children)

It's not just static typing. In an expression like (a b c) the a seems to be able to be a function call, or a variable, and I do not see a way to determine that at a glance, compared to something like a(b, c) or [a, b, c].

Now I understand your confusion better: (a b c) is a symbolic expression which evaluates to something else and will always be read a function call of a with args b and c.

If you wanted to set (a b c) as a list value in of it self you would write (quote (a b c)) or '(a b c) as the syntactic shorthand. This is also an s-expression.

When you write lisp, you're writing s-expressions that will be evaluated later. There are no statements in lisp, only expressions.

Also, do docstrings enforce the types, or are they just comments?

No, they don't enforce types via the interpreter, but they are not comments because they appear in documentation. Lisp has comments in addition to docstrings similar to Python.

Comparing expressions (a b ((c d) e)) and a b c d e, the former actually informs me of the structure at least somewhat.

Yes this is confusing because you have taken out the indentation

(a b
    ((c d)
      e)
)
a b
   c d
   e

This is still unclear, but this is just to demonstrate how to follow lisp code.

Apologies, I have tried looking this up, but I have been unable to find anything that would support this claim. Would you mind directing me to a source?

I can't dig into the specific source, but the macro_rules name comes from scheme's syntax-rules it wasn't an original invention by Rust or taken from C/Cpp. Lisps have also influenced design decisions like functions as first class citizens and closures (lambda expressions).

As in, LISP programs are commonly made to run in parallel with their REPL interfaces? I was under the impression that REPL usually requires for a program to finish executing prior commands.

Nope, the REPL is an evolving, adaptive environment that represents the totality of your program/project. So for example, you have a repl loaded while writing lisp code and you can evaluate an s expression at your cursor and the output will be computed by the repl. It encourages prototyping and iterating on smaller and smaller procedures to create larger ones.

This very much lends itself to favoring functional programming, but imperative lisps can also use the REPL to great effect.

This doesn't mean unit testing/integration tests/debuggers etc are not used, but the Lisp REPL is an example of interactive programming that isn't replicated by other C-likes unless you have heavy IDE support.

[–] Tomorrow_Farewell@hexbear.net 1 points 1 week ago (2 children)

When you write lisp, you're writing s-expressions that will be evaluated later. There are no statements in lisp, only expressions.

Apologies for nitpicking, but did you mean that all statements are expressions in Lisp? If there were no statements, surely it would be impossible to actually make things that do anything other than calculate some results, wouldn't it?

No, they don't enforce types via the interpreter, but they are not comments because they appear in documentation. Lisp has comments in addition to docstrings similar to Python.

Yeah, that is what I did mean when I referred to the possibility of docstrings being mere 'comments'. I excluded their role in documentation, as I was only concerned with their direct effect on the code.

Yes this is confusing because you have taken out the indentation

This seems to contradict the formatting used for examples that I see on the Guile Hoot page, as well as your prior factorial example. Wouldn't that mean that that example should have been formatted as something like the following?

(defun factorial 
  (n &optional 
    (acc 1))
  (if 
    (zerop n) 
    acc
    (factorial 
      (1- n)
      (* acc n))))
[–] hello_hello@hexbear.net 2 points 1 week ago* (last edited 1 week ago)

Apologies for nitpicking, but did you mean that all statements are expressions in Lisp? If there were no statements, surely it would be impossible to actually make things that do anything other than calculate some results, wouldn't it?

The Interpreter produces the side effects required when the program starts (it does the syscalls, state changes, etc) Haskell is a pure functional programming language that is not a lisp that has no statements but it can also make web applications, data crunching tools, and games.

Lisp can be used in an imperative context with mutability, so it's not locked into one style of programming or the other.

This seems to contradict the formatting used for examples that I see on the Guile Hoot page, as well as your prior factorial example. Wouldn't that mean that that example should have been formatted as something like the following?

https://lisp-lang.org/style-guide/

Special forms like "if" and "defun" are highlighted in your editor. There also exists editor plugins that will let you edit lisp through s-expressions (being able to swap two s expressions rather than deleting one and then putting it in the desired place)

This is not the only style guide, each dialect has their own style guide.

The unreadable soup that lisp is may seem to be are macros (which requiring understanding the macro first before using). But macros without context are difficult in any language, not just lisp.

Going back to SXML, there is no special sauce that makes SXML what it is. It simply is a quoted representation of XML tags. There is no API or anything (outside of evaluating SXML to convert it into another representation)

[–] hello_hello@hexbear.net 2 points 1 week ago* (last edited 1 week ago)

Re: readability

(defclass request ()
  ((url :reader request-url
        :initarg :url
        :type string
        :documentation "Request URL.")
   (method :reader request-method
           :initarg :method
           :initform :get
           :type keyword
           :documentation "Request method, e.g :get, :post.")
   (parameters :reader request-parameters
               :initarg :parameters
               :initform nil
               :type association-list
               :documentation "The request parameters, as an association list."))
  (:documentation "A general HTTP request."))

Also OOP can be used in lisp in addition to imperative and functional.