[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Chapter 3.3 of OnLisp --- Functional Interfaces

gengyangcai

9/28/2015 3:37:00 PM


CL-USER 1 > (defun qualify (expr)
(nconc (copy-list expr) (list 'maybe)))
QUALIFY

CL-USER 2 > (let ((x 0)) (defun total (y)
(incf x y)))
TOTAL

CL-USER 3 >
(defun ok (x)
(nconc (list 'a x) (list 'c)))
OK

CL-USER 4 > (defun not-ok (x)
(nconc (list 'a) x (list 'c)))
NOT-OK

CL-USER 5 > (defun anything (x) (+ x *anything*))
ANYTHING

CL-USER 6 > (defun f (x)
(let ((val (g x)))
; safe to modify val here? ))

CL-USER 1 > (defun exclaim (expression) (append expression '(oh my)))
EXCLAIM

CL-USER 2 > (exclaim '(lions and tigers and bears))
(LIONS AND TIGERS AND BEARS OH MY)

CL-USER 3 > (LIONS AND TIGERS AND BEARS OH MY)

Error: Undefined operator LIONS in form (LIONS AND TIGERS AND BEARS OH MY).
1 (continue) Try invoking LIONS again.
2 Return some values from the form (LIONS AND TIGERS AND BEARS OH MY).
3 Try invoking something other than LIONS with the same arguments.
4 Set the symbol-function of LIONS to another function.
5 Set the macro-function of LIONS to another function.
6 (abort) Return to level 0.
7 Return to top loop level 0.

Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.

CL-USER 4 : 1 > (nconc * '(goodness))
(GOODNESS)

CL-USER 5 : 1 > (LIONS AND TIGERS AND BEARS OH MY GOODNESS)

Error: Undefined operator LIONS in form (LIONS AND TIGERS AND BEARS OH MY GOODNESS).
1 (continue) Try invoking LIONS again.
2 Return some values from the form (LIONS AND TIGERS AND BEARS OH MY GOODNESS).
3 Try invoking something other than LIONS with the same arguments.
4 Set the symbol-function of LIONS to another function.
5 Set the macro-function of LIONS to another function.
6 (abort) Return to level 1.
7 Return to debug level 1.
8 Return to level 0.
9 Return to top loop level 0.

Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.

CL-USER 6 : 2 > (exclaim '(fixnums and bignums and floats))
(FIXNUMS AND BIGNUMS AND FLOATS OH MY)

CL-USER 7 : 2 > (FIXNUMS AND BIGNUMS AND FLOATS OH MY GOODNESS)

Error: Undefined operator FIXNUMS in form (FIXNUMS AND BIGNUMS AND FLOATS OH MY GOODNESS).
1 (continue) Try invoking FIXNUMS again.
2 Return some values from the form (FIXNUMS AND BIGNUMS AND FLOATS OH MY GOODNESS).
3 Try invoking something other than FIXNUMS with the same arguments.
4 Set the symbol-function of FIXNUMS to another function.
5 Set the macro-function of FIXNUMS to another function.
6 (abort) Return to level 2.
7 Return to debug level 2.
8 Return to level 1.
9 Return to debug level 1.
10 Return to level 0.
11 Return to top loop level 0.

Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.

CL-USER 8 : 3 > (defun exclaim (expression)
(append expression (list 'oh 'my)))
EXCLAIM
3 Answers

taruss

9/28/2015 5:30:00 PM

0

On Monday, September 28, 2015 at 8:37:07 AM UTC-7, CAI GENGYANG wrote:
> CL-USER 1 > (defun qualify (expr)
> (nconc (copy-list expr) (list 'maybe)))
> QUALIFY
>
> CL-USER 2 > (let ((x 0)) (defun total (y)
> (incf x y)))
> TOTAL
>
> CL-USER 3 >
> (defun ok (x)
> (nconc (list 'a x) (list 'c)))
> OK
>
> CL-USER 4 > (defun not-ok (x)
> (nconc (list 'a) x (list 'c)))
> NOT-OK
>
> CL-USER 5 > (defun anything (x) (+ x *anything*))
> ANYTHING
>
> CL-USER 6 > (defun f (x)
> (let ((val (g x)))
> ; safe to modify val here? ))
>
> CL-USER 1 > (defun exclaim (expression) (append expression '(oh my)))
> EXCLAIM
>
> CL-USER 2 > (exclaim '(lions and tigers and bears))
> (LIONS AND TIGERS AND BEARS OH MY)
>
> CL-USER 3 > (LIONS AND TIGERS AND BEARS OH MY)
>
> Error: Undefined operator LIONS in form (LIONS AND TIGERS AND BEARS OH MY).
> 1 (continue) Try invoking LIONS again.
> 2 Return some values from the form (LIONS AND TIGERS AND BEARS OH MY).
> 3 Try invoking something other than LIONS with the same arguments.
> 4 Set the symbol-function of LIONS to another function.
> 5 Set the macro-function of LIONS to another function.
> 6 (abort) Return to level 0.
> 7 Return to top loop level 0.
>
> Type :b for backtrace or :c <option number> to proceed.
> Type :bug-form "<subject>" for a bug report template or :? for other options.
>
> CL-USER 4 : 1 > (nconc * '(goodness))
> (GOODNESS)
>
> CL-USER 5 : 1 > (LIONS AND TIGERS AND BEARS OH MY GOODNESS)
>
> Error: Undefined operator LIONS in form (LIONS AND TIGERS AND BEARS OH MY GOODNESS).
> 1 (continue) Try invoking LIONS again.
> 2 Return some values from the form (LIONS AND TIGERS AND BEARS OH MY GOODNESS).
> 3 Try invoking something other than LIONS with the same arguments.
> 4 Set the symbol-function of LIONS to another function.
> 5 Set the macro-function of LIONS to another function.
> 6 (abort) Return to level 1.
> 7 Return to debug level 1.
> 8 Return to level 0.
> 9 Return to top loop level 0.
>
> Type :b for backtrace or :c <option number> to proceed.
> Type :bug-form "<subject>" for a bug report template or :? for other options.
>
> CL-USER 6 : 2 > (exclaim '(fixnums and bignums and floats))
> (FIXNUMS AND BIGNUMS AND FLOATS OH MY)
>
> CL-USER 7 : 2 > (FIXNUMS AND BIGNUMS AND FLOATS OH MY GOODNESS)
>
> Error: Undefined operator FIXNUMS in form (FIXNUMS AND BIGNUMS AND FLOATS OH MY GOODNESS).
> 1 (continue) Try invoking FIXNUMS again.
> 2 Return some values from the form (FIXNUMS AND BIGNUMS AND FLOATS OH MY GOODNESS).
> 3 Try invoking something other than FIXNUMS with the same arguments.
> 4 Set the symbol-function of FIXNUMS to another function.
> 5 Set the macro-function of FIXNUMS to another function.
> 6 (abort) Return to level 2.
> 7 Return to debug level 2.
> 8 Return to level 1.
> 9 Return to debug level 1.
> 10 Return to level 0.
> 11 Return to top loop level 0.
>
> Type :b for backtrace or :c <option number> to proceed.
> Type :bug-form "<subject>" for a bug report template or :? for other options.
>
> CL-USER 8 : 3 > (defun exclaim (expression)
> (append expression (list 'oh 'my)))
> EXCLAIM

What is your question?

taruss

9/28/2015 5:43:00 PM

0

On Monday, September 28, 2015 at 8:37:07 AM UTC-7, CAI GENGYANG wrote:
> CL-USER 1 > (defun qualify (expr)
> (nconc (copy-list expr) (list 'maybe)))

Simpler: (append expr (list 'maybe))
If you are going to make a copy of the first argument anyway, there is no
reason to use NCONC instead of APPEND, since APPEND will also make the copy.

> CL-USER 2 > (let ((x 0)) (defun total (y)
> (incf x y)))

You realize that you have no way to find out the value of X independently.
Although I suppose you could always call (TOTAL 0) to find out the current value of X.

What do you want this TOTAL function to accomplish?

> CL-USER 3 >
> (defun ok (x)
> (nconc (list 'a x) (list 'c)))

Simpler: (list 'a x 'c)

> CL-USER 4 > (defun not-ok (x)
> (nconc (list 'a) x (list 'c)))

You realize that this will destructively modify X, which must be a list.


> CL-USER 5 > (defun anything (x) (+ x *anything*))
> ANYTHING

You need to also define *ANYTHING*, presumably with DEFVAR or DEFPARAMETER.

>
> CL-USER 6 > (defun f (x)
> (let ((val (g x)))
> ; safe to modify val here? ))

Depends on what you mean by modify and safe.
Using SETQ or SETF on VAL will always be safe, since it just changes the local
variable binding.
If you destructively modify the object that is bound to VAL then that may or
may not be safe, but that depends on what invariants your program wants to have
and what could be considered safe.

Pascal J. Bourguignon

9/28/2015 6:55:00 PM

0

CAI GENGYANG <gengyangcai@gmail.com> writes:

> CL-USER 1 > (defun qualify (expr)
> [â?¦]
> CL-USER 5 : 1 > (LIONS AND TIGERS AND BEARS OH MY GOODNESS)
>
> Error: Undefined operator LIONS in form (LIONS AND TIGERS AND BEARS OH MY GOODNESS).
> [â?¦]

You keep being an idiot.

We don't need you to run lisp code at OUR REPL, and to debug it locally.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk