libera/#lisp - IRC Chatlog
Search
7:28:59
rendar
can we say that apply internally checks the number of arguments that the functions accepts, and if its 2, and the list of params len > 2, it will act like a reduce
7:36:55
wasamasa
you can translate a function accepting several arguments to a function accepting one argument less
7:42:12
wasamasa
if you want to expose apply to the lisp interpreter, it's slightly bit more complicated
7:51:40
rendar
wasamasa, the problem with `return func(*func_args)` is it works when i call (+ 1 2), but it doesn't when i call (+ 1 2 3)
7:52:23
wasamasa
in scheme (+) returns 0, (+ 1) returns 1, (+ 1 2) returns 3 and (+ 1 2 3) returns 6
7:53:27
wasamasa
you need to implement + in terms of functools.reduce, not apply in terms of functools.reduce
7:54:22
wasamasa
no, you need to look at every individual function you need to implement and decide how
7:54:57
rendar
the point is that in lisp every 2-ary functions like +, -, / and so on, seem to take N args
7:55:27
rendar
a kind of minimal lisp just to insert commands in a system, minimal ability to create functions and macros
7:57:51
wasamasa
you still need to decide how basic arithmetic should behave and how a useful standard library looks like
9:17:31
rendar
also, there must be some internal mechanism that will map (- 1) to an unary not function, and (- 1 1) to 2-ary minus function..
9:19:46
wasamasa
but you might as well just have your minus function check for the number of arguments itself
9:27:37
pjb
(defun - (arg &rest args) (if (null args) (* -1 arg) (+ arg (* -1 (apply (function +) args)))))
9:32:16
sham1
(define - (case-lambda ((x) (negate x)) ((x . ys) (actually-subtract x (reduce + 0 ys)))))
11:49:53
jcowan
As for Scheme not being CL-like, it is far more CL-like than most other Lisps: Interlisp, Picolisp, Clojure. All of them are descendants of Lisp 1.5.
12:11:09
mdhughes_
(- 1) is just equivalent to (- 0 1) of course; it could be implemented as fold from 0, same as +
12:36:00
Alfr
mdhughes_, so you still have to decide based upon how many arguments you get, nothing gained. And then whether you say 0-x or additive inverse of x, doesn't really. I like the second one more, but that may be a personal preference.
12:37:34
aeth
Alfr: anything that + and - are defined to work on, since this is #lisp and not #commonlisp or #scheme :-p
12:37:51
aeth
but we are working on something purely symbolic and much more abstract than anything concrete
12:38:17
aeth
perhaps x and y are true real numbers (or at least, the ones that are computable) rather than floats/rationals/integers
12:40:59
aeth
(which is afaik equivalent to (- (+) A) as long as (+) produces a zero matrix the same size as A)
12:41:52
Alfr
aeth, so, you have +, e, +-inverse? And since you certainly want (+ a b c ..) to be unambiguous, you want + to associative. That group gives you a group, I think.
12:45:12
aeth
yes, we want Abstract Lisp's + to work on groups, while / for more than one argument should be restricted to fields
12:45:18
Alfr
aeth, I also think, that you want to be able to write (+ a b (+ c ..) d ..), so + is also closed. (I always forget this one.)