Xah Talk Show 2025-03-28 Ep636 emacs lisp, change bracket type, design of function arguments

change brackets

xah talk show 2025-03-27 brackets 172522
xah talk show 2025-03-27 brackets 172522
xah talk show 2025-03-27 brackets 172819
xah talk show 2025-03-27 brackets 172819

links

examples of define function

const xadd = ((x,y) => x+y);
console.log( xadd(3,4) )
def xadd(x, y):
	"""add 2 nums"""
	return x + y
print( xadd(3, 4))
# 7
;; define a function

(defun xadd (x y)
  "add 2 numbers"
  (+ x y))

;; call the function
(xadd 3 4)
;; 7

;; HHHH------------------------------

;; now in emacs lisp,
;; any function can be trivially turn into a command,
;; and user can call it by Meta-x (normally Alt+x)

;; you can do this by adding
;; (interactive)
;; right after the docstring

(defun xadd3and4 ()
  "add 2 numbers"
  (interactive)
  (insert (number-to-string (+ 3 4))))

;; HHHH------------------------------

;; there is a question, how do you pass the function argument
 ;; when you call it interactively

;; there are many ways
;; the simplest and naive way, is to simply promp user,
;; and put the args inside list inside interactive

(defun xadd (x y)
  "add 2 numbers"
  (interactive (list 3 4))
  (insert (number-to-string (+ x y))))

;; here's is how to ask user for arguments

(defun xadd (x y)
  "add 2 numbers"
  (interactive (list
                (read-number "enter first number:")
                (read-number "enter second number:")))
  (insert (number-to-string (+ x y))))

;; 10

;; fantastic

design of the semantics of function's aruments

design of the syntax of function's aruments

example of unix fuckup

here are illustrations of the complete unix fuckup in both the function argument semantics and syntax

ps auwwx
ps -ef
ls -al
xah talk show 2025-03-28 unix ps 1feb4
xah talk show 2025-03-28 unix ps 1feb4
xah talk show 2025-03-28 unix ps 1fef1
xah talk show 2025-03-28 unix ps 1fef1