lisp syntax

lisp syntax

GeryKnee
Advocate Advocate
931 Views
8 Replies
Message 1 of 9

lisp syntax

GeryKnee
Advocate
Advocate

where is the fault in following ???


(defun fnNotify (aMessage)
(princ (strcat "\n" aMessage))
(princ "\n" )
(princ)
)

(defun xx ()
(setq Temp (getvar "USERS1")) ;; get the double stored in "USERS1"
(fnNotify (rtos 0.001 (Temp)))
(princ)
)

0 Likes
Accepted solutions (1)
932 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant

What the USERS1 stores? A unit or a number as string?

(rtos 0.001 HereHasToBeAnInteger)

Also it should be (rtos 0.001 Temp), but integer-temp

Message 3 of 9

GeryKnee
Advocate
Advocate

Hello Sir,

take a look at this :::

 


(defun fnNotify (aMessage)
(princ (strcat "\n" aMessage))
(princ "\n" )
(princ)
)

(defun xx ()
(setvar "USERI1" 10)
(setq Temp (getvar "USERI1"))
(fnNotify (itos Temp));; itos??? a routine converting integer to string
(princ)
)

Thanks,

Gery

0 Likes
Message 4 of 9

ВeekeeCZ
Consultant
Consultant

ItoA is the function you need.

No other issue.

0 Likes
Message 5 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

You might also add (vl-print-to-string data) which converts any data type to string.

 

(defun fnNotify (aMessage)
  (princ (strcat "\n" (vl-princ-to-string aMessage)))
  (princ "\n" )
  (princ)
  )

(defun xx ()
  (setvar "USERS1" "10")
  (fnNotify (getvar "USERS1"))
  (princ)
  )

(defun xx1 ()
  (setvar "USERI1" 10)
  (fnNotify (getvar "USERI1"))
  (princ)
  )

 

Message 6 of 9

GeryKnee
Advocate
Advocate

Thank you very much,

Regards,

Gery

0 Likes
Message 7 of 9

GeryKnee
Advocate
Advocate

Plese Sir,

trying the following simple code


(defun fnNotify (aMessage)
(princ (strcat "\n" (vl-princ-to-string aMessage)))
(princ "\n" )
(princ)
)

(defun c:xxx()
(fnNotify ("1"))
(princ)
)

 

GeryKnee_0-1616839914429.png

 

 

 

I get the answer

 

erroc, bad function "1"

what happens???

 

 

 

0 Likes
Message 8 of 9

Moshe-A
Mentor
Mentor

@GeryKnee ,

 

First of all

(getvar "userS1") return   a string                  (same as  userS1-userS5)

(getvar "userR1") return   a real number       (same as userR1-userR5)

(getvar "userI1")  return an integer number (same as  userI1-userI5)

 

Second (fnNotify ("1"))

in lisp format the first item inside list (in parentheses) should be a function name

cause "1" is not, you get bad function.

 

it should be

(fnNotify "1")

 

Moshe

 

Message 9 of 9

john.uhden
Mentor
Mentor

@ВeekeeCZ 

Good work, sir.  You are being quite helpful today.

John F. Uhden

0 Likes