john_ Posted June 9, 2009 Share Posted June 9, 2009 I'm just starting to learn this lisp stuff so please go easy one me. I'm having a slight issue maybe someone can help me understand. Command: (setq test (strcat "hello" "\n " "there")) "hello\n there" I read in the help documentation that \n is a new line but it doesn't display as such with my example. Am I misunderstanding how to use the new line character. I'm just playing around learning this so it has no meaning but I was just trying to display hello there Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 9, 2009 Share Posted June 9, 2009 Hi John, "\n" is indeed the New line character, try running these to experiment: (defun c:test () (princ "\nMy Name is \nJohn") (princ)) Hope this helps Quote Link to comment Share on other sites More sharing options...
Freerefill Posted June 9, 2009 Share Posted June 9, 2009 Lee, does (princ) and (strcat) process control codes differently? I noticed a similar thing when I tried: (strcat "\010" " " "\010") That is to say, I couldn't princ it, I -had- to strcat it in order for it to work the way I wanted it to. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 9, 2009 Share Posted June 9, 2009 Octal Codes seem to work for me - for example: (princ "\100Lee Mac") (princ) Returns: @Lee Mac But Control Characters are harder to test for, so I'm not sure. Quote Link to comment Share on other sites More sharing options...
David Bethel Posted June 9, 2009 Share Posted June 9, 2009 (strcat) doesn't evaluate the code, it just concatenates the strings. (princ) evaluates the string control characters prior to displaying them You can see the biggest differences between (prin1) (princ) and (print) when outputting to files [b][color=BLACK]([/color][/b]setq wf [b][color=FUCHSIA]([/color][/b]open [color=#2f4f4f]"text.txt"[/color] [color=#2f4f4f]"w"[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]princ [color=#2f4f4f]"\nPRINC call"[/color] wf[b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]write-line [color=#2f4f4f]" - "[/color] wf[b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]prin1 [color=#2f4f4f]"\nPRIN1 call"[/color] wf[b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]write-line [color=#2f4f4f]" - "[/color] wf[b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]print [color=#2f4f4f]"\nPRIN1 call"[/color] wf[b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]close wf[b][color=BLACK])[/color][/b] -David Quote Link to comment Share on other sites More sharing options...
Beeftimer Posted January 30, 2015 Share Posted January 30, 2015 What I am having a hard time understanding is why the \n is needed before "My name is..." I have run (defun c:test () (princ "\nMy Name is \nJohn") (princ)) and (defun c:test () (princ "My Name is \nJohn") (princ)) without seeing any difference at all. I see several examples of this when learning LISP and it is very confusing to me. Isn't the first \n redundant? Why do we put it there? Quote Link to comment Share on other sites More sharing options...
CheSyn Posted January 30, 2015 Share Posted January 30, 2015 Using "\n" in larger routines will split lines between commands, providing similar behavior/appearance to native AutoCAD commands. You will not notice a difference in the example you posted. Beeftimer, try running the following: (defun c:test () (setq e (car (entsel "\nSelect an entity : ")) i (getpoint "Select a point : ") ) (princ) ) vs (defun c:test () (setq e (car (entsel "\nSelect an entity : ")) i (getpoint "\nSelect a point : ") ) (princ) ) Do you notice the difference when progressing through the steps? Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 31, 2015 Share Posted January 31, 2015 Try alert also for messages. (alert (strcat "Hello" "\nworld")) This is my get a value using a dialouge. Code (ah:getval "Enter the size" 6 5) Getval is preloaded. ;; Input Dialog box with variable title ;; By Ah June 2012 ;; original concept by Alan JT ;; code (ah:getval title width limit) (defun AH:Getval (title width limit / fo) (setq fname "C://acadtemp//getval.dcl") (setq fo (open fname "w")) (write-line "ddgetval : dialog {" fo) (write-line " : row {" fo) (write-line ": edit_box {" fo) (write-line (strcat " key = " (chr 34) "sizze" (chr 34) ";") fo) (write-line (strcat " label = " (chr 34) title (chr 34) ";" ) fo) ; these can be replaced with shorter value etc ;(write-line " edit_width = 18;" fo) ;(write-line " edit_limit = 15;" fo) (write-line width fo) (write-line limit fo) (write-line " is_enabled = true;" fo) (write-line " }" fo) (write-line " }" fo) (write-line "ok_cancel;}" fo) (close fo) (setq dcl_id (load_dialog "c:\\acadtemp\\getval")) (if (not (new_dialog "ddgetval" dcl_id)) (exit)) (action_tile "sizze" "(setq item $value)(done_dialog)") (mode_tile "sizze" 3) (start_dialog) ; returns the value of item ) Quote Link to comment Share on other sites More sharing options...
David Bethel Posted January 31, 2015 Share Posted January 31, 2015 See if this helps : (defun c:test () (princ "Line 1: ") (princ "\nMy Name is \nJohn") (princ)) (defun c:test () (princ "Line 2 : ") (princ "My Name is \nJohn") (princ)) -David Quote Link to comment Share on other sites More sharing options...
Beeftimer Posted February 2, 2015 Share Posted February 2, 2015 (edited) Yes, I do see the difference very clearly with your examples. I understood the difference between the two, but my question was regarding why it was needed in the example that I posted? From what you said, I'm leaning that, yes, the first \n is, in fact, redundant and/or unnecessary in that example? Is it just standard practice to include it there so as to create good habits? And thank you for your response. Using "\n" in larger routines will split lines between commands, providing similar behavior/appearance to native AutoCAD commands. You will not notice a difference in the example you posted. Beeftimer, try running the following: (defun c:test () (setq e (car (entsel "\nSelect an entity : ")) i (getpoint "Select a point : ") ) (princ) ) vs (defun c:test () (setq e (car (entsel "\nSelect an entity : ")) i (getpoint "\nSelect a point : ") ) (princ) ) Do you notice the difference when progressing through the steps? Edited February 2, 2015 by Beeftimer etiquette Quote Link to comment Share on other sites More sharing options...
CheSyn Posted February 2, 2015 Share Posted February 2, 2015 Yes, I do see the difference very clearly with your examples. I understood the difference between the two, but my question was regarding why it was needed in the example that I posted? From what you said, I'm leaning that, yes, the first \n is, in fact, redundant and/or unnecessary in that example? Is it just standard practice to include it there so as to create good habits? And thank you for your response. Exactly Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 3, 2015 Share Posted February 3, 2015 my question was regarding why it was needed in the example that I posted? From what you said, I'm leaning that, yes, the first \n is, in fact, redundant and/or unnecessary in that example? Is it just standard practice to include it there so as to create good habits? You can't know in advance the text which may have been previously printed to the command-line and which may obscure your printed message, hence it is usually wise to print to a new-line. For example, consider a case in which the user has evaluated your function from another program: (defun c:test () (princ "My Name is \nJohn") (princ)) [color=gray]Command:[/color] (progn (princ "\nSome random text") (c:test)) Some random textMy Name is John Versus: (defun c:test () (princ "\nMy Name is \nJohn") (princ)) [color=gray]Command:[/color] (progn (princ "\nSome random text") (c:test)) Some random text My Name is John Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.