See the top rated post in this thread. Click here

Results 1 to 7 of 7

Thread: Difference Between PRINT, PRINC & PRIN1?

  1. #1
    Member
    Join Date
    2001-05
    Posts
    30
    Login to Give a bone
    0

    Default Difference Between PRINT, PRINC & PRIN1?

    Could someone please expalin the difference between the following ALisp functions?:
    PRINT
    PRINC
    PRIN1

    Is there any functional difference at all? If so, then when should one be used over the others, etc?

    Thanks!

  2. #2
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Difference Between PRINT, PRINC & PRIN1?

    Code:
    prin1
    (prin1 [expr [file-desc]])
    Arguments
    expr A string or AutoLISP expression. Only the specified expr is
    printed; no newline or space is included.
    file-desc A file descriptor for a file opened for writing.
    Return Values
    The value of the evaluated expr. If called with no arguments, prin1 returns a
    null symbol.
    Returns the UCS 3D point at a specified angle and distance from a point
    Prints an expression to the command line or writes an expression to an open file
    142 | AutoLISP Reference
    Used as the last expression in a function, prin1 without arguments results in
    a blank line printing when the function completes, allowing the function to
    exit “quietly.”
    Examples
    Command: (setq a 123 b '(a))
    (A)
    Command: (prin1 'a)
    AA
    The previous command printed A and returned A.
    Command: (prin1 a)
    123123
    The previous command printed 123 and returned 123.
    Command: (prin1 b)
    (A)(A)
    The previous command printed (A) and returned (A).
    Each preceding example is displayed on the screen because no file-desc was
    specified. Assuming that f is a valid file-descriptor for a file opened for writing,
    the following function call writes a string to that file and returns the
    string:
    Command: (prin1 "Hello" f)
    "Hello"
    If expr is a string containing control characters, prin1 expands these characters
    with a leading \, as shown in the following table:
    Control codes
    Code Description
    \\ \ character
    \" " character
    \e Escape character
    \n Newline character
    \r Return character
    \t TAB character
    \nnn Character whose octal code is nnn
    princ | 143
    The following example shows how to use control characters:
    Command: (prin1 (chr 2))
    "\002""\002"
    SEE ALSO “Displaying Messages” in the Visual LISP Developer’s Guide.
    princ
    (princ [expr [file-desc]])
    This function is the same as prin1, except control characters in expr are
    printed without expansion. In general, prin1 is designed to print expressions
    in a way that is compatible with load, while princ prints them in a way that
    is readable by functions such as read-line.
    Arguments
    expr A string or AutoLISP expression. Only the specified expr is
    printed; no newline or space is included.
    file-desc A file descriptor for a file opened for writing.
    Return Values
    The value of the evaluated expr. If called with no arguments, princ returns a
    null symbol.
    SEE ALSO “Displaying Messages” in the Visual LISP Developer’s Guide.
    print
    (print [expr [file-desc]])
    This function is the same as prin1, except it prints a newline character before
    expr, and prints a space following expr.
    Arguments
    expr A string or AutoLISP expression. Only the specified expr is
    printed; no newline or space is included.
    Prints an expression to the command line, or writes an expression to an open file
    Prints an expression to the command line, or writes an expression to an open file
    144 | AutoLISP Reference
    file-desc A file descriptor for a file opened for writing.
    Return Values
    The value of the evaluated expr. If called with no arguments, print returns a
    null symbol.

  3. #3
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Difference Between PRINT, PRINC & PRIN1?

    Quote Originally Posted by jf1725 View Post
    Could someone please expalin the difference between the following ALisp functions?:
    PRINT
    PRINC
    PRIN1

    Is there any functional difference at all? If so, then when should one be used over the others, etc?

    Thanks!
    AutoCAD developer help is a good source to look at for the differences.

  4. #4
    Member
    Join Date
    2001-05
    Posts
    30
    Login to Give a bone
    0

    Default Re: Difference Between PRINT, PRINC & PRIN1?

    Quote Originally Posted by ccowgill View Post
    AutoCAD developer help is a good source to look at for the differences.
    Chris,
    Pardon my ignorance, but where do I go to access "AutoCAD Developer Help". (I'm running ACAD 2010.) I opened the Visual LISP editor (VLIDE) and went to the Help and checked the descriptions for those three functions - but the descriptions were exactly the same for all three. I do see that the heading on the Help dialog box reads as follows:
    "AutoCAD 2010 Help: Developer Documentation". Is this the same thing that you mentioned?

    Thanks,

    John

  5. #5
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Difference Between PRINT, PRINC & PRIN1?

    Quote Originally Posted by jf1725 View Post
    Chris,
    Pardon my ignorance, but where do I go to access "AutoCAD Developer Help". (I'm running ACAD 2010.) I opened the Visual LISP editor (VLIDE) and went to the Help and checked the descriptions for those three functions - but the descriptions were exactly the same for all three. I do see that the heading on the Help dialog box reads as follows:
    "AutoCAD 2010 Help: Developer Documentation". Is this the same thing that you mentioned?

    Thanks,

    John
    Yes, that is the correct location, if you select the actual word (should be in blue) it will give you a more detailed description of each function.

  6. #6
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Difference Between PRINT, PRINC & PRIN1?

    Easiest way for me, select the particular keyword in the VLIDE (or VLISP - same thing ) editor. Then press Ctrl+F1 ... it opens the help for that particular keyword (if found).

    Long story short (or maybe longer ): they all 3 send a string to either the command line area (note it doesn't send a command, just a message). Or (if specified) to a file.
    • The princ function sends a string after formatting any contol characters. E.g. (princ "\"this is quoted\"") will show as "this is quoted" on the command line.
    • The prin1 function does the same without formatting. E.g. (prin1 "\"this is quoted\"") will show as "\"this is quoted\"". This is usually used when sending to a file so you can later use the read function to get the same value. Also say you have a list of strings, it'll send the text to the file so a later read would produce the same list of strings - princ will ommit the quotes and the read would fail.
    • The print function does the same as the prin1, but prefixes the string with a newline "\n" (which is formatted). This so that you can send a control code string to a new line in a file in one instruction, otherwise you'd have to do a princ for the new line, then a prin1 for the data.
    • There's also the prompt function which does exactly the same as princ with 2 caveats:
      • It can't send to a file (only the command line)
      • It has to have some text to send to the command line. The princ can be used without any string - this is usually wanted when you end a defun with (princ) so nothing is displayed on the command line. Otherwise the last line of the defun will basically issue a prin1 with its value.
    I tend to ignore prompt and use princ instead. But the other 2 have their uses and I've used them many a time.

  7. #7
    100 Club
    Join Date
    2003-06
    Location
    North Dallas
    Posts
    168
    Login to Give a bone
    1

    Default Re: Difference Between PRINT, PRINC & PRIN1?

    Don't forget terpri. It won't write to files either. It's a stand alone function that sends a new line to the command line. Just like (princ "\n") except it returns nil.

Similar Threads

  1. (princ)
    By David van Erk in forum AutoLISP
    Replies: 4
    Last Post: 2007-08-09, 09:27 PM
  2. princ in dynamic input
    By bart.84601 in forum AutoLISP
    Replies: 1
    Last Post: 2005-10-11, 04:56 PM
  3. PRINT WINDOW & PRINT SETTINGS PER SHEET
    By neb1998 in forum Revit Architecture - Wish List
    Replies: 1
    Last Post: 2005-07-01, 07:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •