guitarvydas
09/04/2025, 2:34 PMhumane syntax???:
----------------
break down member (x, list) -> ([#found | #not-found], value) {
finish when list is empty { ^ #not-found, ɸ }
finish when x in list { ^ #found, list }
decompose list' <- rest (list) {
^ again (x, list')
}
}
break down append (x, list) -> value {
finish when list is empty { ^ x }
decompose «item» <- first (list), «list'» <- rest (list) {
^ prepend «item» onto again (x, «list'»))
}
}
inhumane syntax:
----------------
(defun my_member (x lis)
(cond ((null lis) (values nil nil))
((eq x (car lis)) (values t lis))
(t (my_member x (cdr lis)))))
(defun my_append (lis x)
(cond ((null lis) x)
(t (cons (car lis) (my_append (cdr lis) x)))))
[aside: "send ..." sends something forward asynchronously instead of returning it synchronously to the caller and unblocking the caller]
less-inhumane syntax involving async ports:
-------------------------------------------
break down member (x, list) output ports: { success: [#found | #not-found], value: object } {
finish when list is empty { send success: #not-found, send value: ɸ }
finish when x in list { send success: #found, send value: list }
decompose list' <- rest (list) {
^again (x, list')
}
}
break down append (x, list) output port: { value: object } {
finish when list is empty { send value: x }
decompose «item» <- first (list), «list'» <- rest (list) {
send value: prepend «item» onto ^again (x, «list'»))
}
}
suggestions / comments?Kartik Agaram
member and append, respectively:
i := list.lob;
do
i <= list.hib and list(i) != x -> i := i+1
od
{i now describes where to find x, if valid}
list:hiext(x)
(At least as of 1977, Dijkstra doesn't seem to think about function boundaries at all.)
(Dijkstra recommended designing data structures out of arrays, in the way Lisp designs them out of cons pairs.)Russell Leggett
09/04/2025, 5:26 PMguitarvydas
09/04/2025, 6:33 PMKartik Agaram
guitarvydas
09/04/2025, 7:18 PMKartik Agaram
Kartik Agaram
Misha A
09/06/2025, 11:07 AMeq t car cdr values are. But those are names, not structure, not syntax. (ok, maybe values is somehow syntax, I don't know why it is there, what it does, and why would I care to have there anything other than yes or no )
Here is the clojure example (notice I redefined only 3 words, and honestly, I think true false defn would be ok w/o substituting them)
;; defn renaming needs to be done differently, via new defmacro, but it can be done globally once, and here it just illustrates the point: "keep the structure, use better names":
(let [NO false
YES true
new-function defn]
(new-function is-x-in-list? [x list]
(if (empty? list)
NO
(if (= x (first list))
YES
(is-x-in-list? x (rest list))))))
It has the same structure as vanilla lisp samples, but much more "humane" (more widely recognizable names (to make 'em even more "humane" – maybe replace with chinese mandarin))
It explicitly has different types of words grouping: () and []
My mom would still have questions, but way fewer than in case of "humane" and vanilla lisp samples.
On the other hand, questions to the "humane" samples I have (to slightly better understand semantics, and maybe to try to write my own fns in this syntax):
• why there are commas there, but not here?
• what # ^ ɸ ' | -> <- are?
• where does function name ends and arg name starts?
• why some args are in () and some are inline?
• I presume [] is a grouping around "regex or", and () - around return type? (try to explain it to my mom)
• why «» in the second sample but not in first?
• is break down a part of fn name or some keywords? why have them? what other options are? are those required?
• if ^ is return indicator, why say finish ? if finish is return - why say ^ ?
• ^ is in every {}, is it required? are those separate concepts, or is it just grouping syntax {^ ...}?
• would « and » be the same as " " or do I need to find them on my keyboard?
• is ɸ – some constant? if yes, why not #ɸ (because #found seems like a constant, and # seems like a way to mark constants). if not a constant, but some type (like value presumably is, can there be different ɸ ? (assuming that's an empty set. but we receive list (something sequential) and return set? huh.)
• is )) in (x, «list'»)) - a typo? or some syntactic thing?
• there are commas , between words in { ^ #found, list } , but not right after ^ , is comma - separating args, and args are not in parens (see decompose and ^ ), but rest (list) seems like a function call, with parens... huh.
• So if ^ is a fn call, how do I start another fn call after ^ (how do I stop the args)? Or is ^ – a syntactical keyword? Should it be be the last "line" in {} block? Why last decompose "line" in both samples is without ^ ? does {} "returns" ^ inside of it?
• there are commas , between words in { ^ #found, list } , but not between 2 finish lines. why?
(and few more :) )Ivan Morén
09/20/2025, 2:37 AM