Jump to content

Failing at simple functions


MtAverest

Recommended Posts

I am new to lisp and programming in general. I get the basic gist and i'm not very proficient at reading it yet.

 

I have 2 major issues. I have a hard time understanding samples given when researching issues i'm having, and no matter how hard I try I just cant seem to understand Arguments.

 

I am also working on a very basic function:

 

(defun c:Burnbot ( / )
    (GetN)
    (Insult)
)
    (defun GetN ( / )
        (princ "\nHello there.")
        (princ)
        (setq ans (read (getstring "\nHey what's your name big guy?")))
    )
    (defun Insult ( / que an mrk )
        (setq ans an)
        (setq que "\nWhat kind of a name is")
        (setq mrk "?\n")
        (princ (list que an mrk))
        (princ)
    )
    (princ "\nInsult Loading...")
    (princ)

 

Output:

(
What kind of a name is nil ?
)

 

This is the closest I have gotten to success. But I just cannot get this variable to load. I've tried adding some of these to my different argument areas but have had only errors. I would appreciate it if anyone can tell me whats going on or/and if anyone can tell me where i can find a comprehensive guide to arguments.

Link to comment
Share on other sites

Something like 

(defun c:Burnbot ( / )
    (defun GetN ( / )
        (princ "\nHello there.")
        (princ)
        (setq ans (getstring "\nHey what's your name big guy?"))
    )
    (defun Insult (ans / que an mrk )
        (setq que "\nWhat kind of a name is ")
        (princ "\nInsult Loading...")
        (princ (Strcat que " " ans " ?"))
        (princ "\n") 
    (princ "\nInsult Loading...")
   )  
    (GetN)
    (If (/= ans nil )
	(Insult ans)
	(Alert "\nWhat kind of a name is nil ?")
	)	
	(princ)
)

 

  • Like 1
Link to comment
Share on other sites

Maybe this helps:

(defun GetNumber (str)
  (getreal str)
)

(defun AddTwoNumbers (num1 num2)
  (+ num1 num2)
)

(defun c:Test ( / num1 num2 res)
  (if
    (and
      (setq num1 (GetNumber "\nFirst number: "))
      (setq num2 (GetNumber "\nSecond number: "))
    )
    (progn
      (setq res (AddTwoNumbers num1 num2))
      (princ (strcat "\nThe total is: " (rtos res)))
    )
  )
  (princ)
)

 

Edited by Roy_043
Edit: Forgot to localize res.
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 12/6/2019 at 3:57 PM, BIGAL said:

Something like 


(defun c:Burnbot ( / )
    (defun GetN ( / )
        (princ "\nHello there.")
        (princ)
        (setq ans (getstring "\nHey what's your name big guy?"))
    )
    (defun Insult (ans / que an mrk )
        (setq que "\nWhat kind of a name is ")
        (princ "\nInsult Loading...")
        (princ (Strcat que " " ans " ?"))
        (princ "\n") 
    (princ "\nInsult Loading...")
   )  
    (GetN)
    (If (/= ans nil )
	(Insult ans)
	(Alert "\nWhat kind of a name is nil ?")
	)	
	(princ)
)

Thank you that worked!

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...