Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - lyl

#1
A good solution! Then, what or where is use of "SW_SHOW" in your code?
#2
I use a function "f" to store data by calling another function "g" like this:
(define (g (x y)) x)
(define (f data)
  (setf (nth '(0 0 1) g) data)
  )
 
;;test:
(f 1)
(g) ;; -> 1  Right. This is what I want.
(g) ;; -> 1  Right. This is what I want.
(f '(+ 1 2))
(g) ;; -> 3  This is not what I want. I can't understand why the quoted list '(+ 1 2) is evaluated?. I just want to get the list itself '(+ 1 2)


By contrast,
(define (g x) x)
(define (f data) (g data))
(f '(+ 1 2)) ;; -> (+ 1 2)   The list is not evaled.


Is there a better way to prevent this kind of unwanted eval during the parameter transfer?
#3
newLISP in the real world / Setup functions by setq
August 27, 2020, 10:54:17 PM
I'd like to make a series of functions whose names come from a list, as shown by the following codes:
(setq a '(a1 a2))
(dolist (x a)
  (let (z $idx)
    (setq x (lambda(y) z))
    ))

what I want is to get two functions

a1: (lambda (y) 0)

a2: (lambda (y) 1)

But I fail.

What's wrong with my code, and how to solve it?
#4
Whither newLISP? / Re: "place" in the function "inc"
August 27, 2020, 10:31:09 PM
Many thanks.

Still, how is the lambda list updated in my example? Or, which element of the lambda list is changed by inc?
#5
Whither newLISP? / "place" in the function "inc"
August 26, 2020, 02:56:32 AM
The meaning of "place" in the syntax: (inc place [num]) is:

either a symbol or a place in a list structure holding a number, or a number returned by an expression.(from the newlisp manuel)



I still don't quite understand the real meaning of "place", as in the following code coming from 《Code Patterns in newLISP》:
;; sum accumulator
(define (sum (x 0)) (inc 0 x))

(sum 1)    → 1
(sum 2)    → 3
(sum 100)  → 103
(sum)      → 103

sum  → (lambda ((x 0)) (inc 103 x))


In this example, what is the "place, and why"?
#6
Many thanks! But where is the value stored in the expression "(setq 'f 100)"
#7
I wonder where or how I can get the value which is assign by setq to a symbol like this:
(setq 'f 100)
'f ;;-> f
''f ;;->'f

How can I get the value 100?
#8
Thank you, cameyo.  I think the argument "lst" of "f" has been evaled during the call of (f a), so why must  it be evaled again by "letex" in function body ?

And could you please give more information about the function "typeof"?
#9
Then, in the following example
(define(f lst)
  (+ lst 1))

(setq a '(+ 2 3))
(f a)


As arguments of function in lisp are evaled first, I think (f a) is the same as (+ (+ 2 3) 1) which should be 6, but what I get is: "ERR: value expected in function + : (+ 2 3)". Why?
#10
Thank you,  cameyo.

In my example, the expression that is to be evaled is the last element in the list which make it possible to use (setf (last lst)...) evaluating the expression. I wonder if there is an universal method to evluating any expression at any position in a list. Here I'd like give another example:



(setq lst '(set "outcome" (+ 1 2) dollars)



in which such a string: "set "outcome" 3 dollars" is wanted.



PS:

I think (list ...) may be a method, but thinking of those elements that can not be evaluated, it's a bit complicated.
#11
(setq a "time")

(setq b '(set xlabel a))



My question is:

how to design a function to transfer a list("b" in this example) into a string. That is to say, replace the parentheses of b with quotation marks to get "set xlabel "time"".
#12
Oh, I understand it! @rickyboy And learn a lot from you. I will use "apply" more carefully.
#13
Thank you so much for this detail explaination.

As you say, "so, you end up passing a symbol as the second argument to append".

The symbol 'var which is passed to "append" has been binded to "b", why is the evaluator not able to see it?

Dose that mean each element of a list which will be passed to a function by "apply" must be evaluated first? And is this a mechanism from "lisp" or from "newlisp"?
#14
First example:
(setq var "b")
(apply append '("a" var)) ;; I believe the result will be "ab", but what I get is error message.


Second example:
(setq var "b")
(append "a" var);; -> "ab"


I think the two examples are equivalent, but it seems not. Why? And why the first example is a wrong way to use "append" and how to make "apply append" work?
#15
A key value(integer) can be obtained by the built-in function "char".

For example,
(char "a")          → 97
My question is: How to  obtain the value of combinated keys like this:

(myfunc "ctrl a") which means "CTRL + a" . And also  "CTRL+Alt+a" , "CTRL+SHIFT+a" are wanted.

Thank you.