john_ Posted May 22, 2009 Posted May 22, 2009 can anyone tell me how i would go about printing a simple text file using lisp? im not talking about printing acad text to a file im specifically looking to add a button to my tool bar that when press ed it will print a specific text file. (.txt) thanks Quote
The Buzzard Posted May 22, 2009 Posted May 22, 2009 Hi John, Welcome to the Forum. Have a moderator move your post to AutoLISP, VBA, the CUI & Customisation You can have Lisp questions easily answered there. Quote
john_ Posted May 22, 2009 Author Posted May 22, 2009 Hi and thanks How do I get a moderator to move it? Quote
The Buzzard Posted May 22, 2009 Posted May 22, 2009 You can send a private message to any moderator. They do not want you to duplicate your message. Or I can contact a moderator for you. I will contact one for you. Quote
The Buzzard Posted May 22, 2009 Posted May 22, 2009 John, I sent a message for you, Please give it a little time. Quote
Commandobill Posted May 26, 2009 Posted May 26, 2009 I believe it would be easier if it were a word document and not your basic .txt file. I may be wrong. Quote
Se7en Posted May 26, 2009 Posted May 26, 2009 here are two quick methods for reading and displaying text on the command line from a text file. ( (lambda ( f / ) (defun pars (s f) ;; Adopted from: ElpanovEvgeniy (if s (cons s (pars (read-line f) f)) (close f)) ) (princ "\n\n") (mapcar '(lambda (x) (write-line x)) (pars (read-line f) f)) (princ) ) (open "C:\\MyFile.txt" "R") ) ( (lambda ( f / line ) (princ "\n\n") (while (setq line (read-line f)) (write-line line)) (princ) ) (open "C:\\MyFile.txt" "R") ) Quote
Lee Mac Posted May 26, 2009 Posted May 26, 2009 I love that "pars" function - I saw it used at the Swamp a few times - Elpanov is a genius But as for the OP's question - I wasn't certain as to whether he meant print to command-line, file or actually use LISP to print a piece of paper... Quote
Se7en Posted May 26, 2009 Posted May 26, 2009 I love that "pars" function - I saw it used at the Swamp a few times - Elpanov is a genius But as for the OP's question - I wasn't certain as to whether he meant print to command-line, file or actually use LISP to print a piece of paper... `pars' is very simple recursion. I cut and paste code and a line like (mapcar '(lambda ( x ) (write-line... is easier then typing the while statement method. The real genius comes in at how the code is ORGANIZED using the two different methods not the code itself. For your homework, tell me what kind or procedure `pars' is. ~ I wasn't sure so i choose the easy route. Quote
Lee Mac Posted May 26, 2009 Posted May 26, 2009 For your homework, tell me what kind or procedure `pars' is. ~ I'm inclined to say "recursive", but you already mentioned that so it can't be that easy... Quote
Se7en Posted May 26, 2009 Posted May 26, 2009 *sigh* ...Don't make me hit you! It is a recursive procedure using a ____ process. *psssst Hint:* Go get that substitution model write up i gave you. Quote
David Bethel Posted May 26, 2009 Posted May 26, 2009 This is a very old routine by Duff Kirkland ( modified to accept all file type extensions ) -David DDTYPE.DCL DDTYPE.LSP Quote
Lee Mac Posted May 26, 2009 Posted May 26, 2009 *sigh* ...Don't make me hit you! Haha, you can try but you might break your monitor... It is a recursive procedure using an iterative process. *psssst Hint:* Go get that substitution model write up i gave you. I did have to take a quick look at it... Quote
Se7en Posted May 26, 2009 Posted May 26, 2009 linear. A tip to determine if it is linear or iterative is to check to see if there is a process yet to be completed after the procedure calls itself. ... (cons ;; construct a list s (pars (read-line f) f)) ;; call itself ... The CONS (a list) has to be evaluated AFTER it calls itself so it is linear (Remember: Lisp is evaluated inside out). Sub model: (do something) (do something (do something)) (do something (do something (do something))) (do something (do something (do something (do something))) ... (do something (do something)) (do something) What you should be thinking to yourself when you see this is: "If there is a lot of information to be processed, it can be a lot of data on the stack so I have to be careful using it." A recursive procedure using an iterative process is sometimes called a "Tail recursive" procedure. Tail recursive procedures are a bit confusing (I have problems with them myself) but 99% of the recursive AutoLisp procedures you see will be using a linear process. A recursive procedure using an iterative process' sub model would look like this: (do something) (do something) (do something) (do something) ... (do something) Anyways, that's awesome that you looked. I refer to it all the time myself but i would be happy if you can find some use for it too. Quote
Lee Mac Posted May 26, 2009 Posted May 26, 2009 Thanks for the information, I do want to understand these things - but they are sometimes hard to envision step by step. Judging by your explanation, I don't think I've actually seen an iterative process (tail-recursive)... but I have seen quite a few linear ones... For example, I use this quite often (originated from Gile me thinks...) (defun list->3D-point (lst) (if lst (cons (list (car lst) (cadr lst) (caddr lst)) (list->3D-point (cdddr lst)))) I did have one question though: What determines the "stack"? Is it the amount of RAM on the computer? or is it to do with something else? Or am I way off the mark on this one... Quote
Se7en Posted May 26, 2009 Posted May 26, 2009 As far as i can tell (ive seen contradicting definitions) is that its the amount of memory (RAM) that the Windows OS allocated to the AutoCAD program upon start up (but i dont know for sure ...I just think of it as a black box of memory). If you find a good def pass it on please. Sure you have. I have an example in that write up. (map-car-iter (lambda (x) (+ x 1)) '(1 2 3) ) (defun map-car-iter ( proc lst) (map-iter '() proc lst) ) (defun map-iter (sofar proc lis) (if (null lis) (reverse sofar) (map-iter (cons (proc (car lis)) sofar) proc (cdr lis))) ) Quote
Lee Mac Posted May 26, 2009 Posted May 26, 2009 Sure you have. I have an example in that write up. (map-car-iter (lambda (x) (+ x 1)) '(1 2 3) ) (defun map-car-iter ( proc lst) (map-iter '() proc lst) ) (defun map-iter (sofar proc lis) (if (null lis) (reverse sofar) (map-iter (cons (proc (car lis)) sofar) proc (cdr lis))) ) Blimey, that is a tough one to figure out - I'd better take another look at that write-up... Quote
Lee Mac Posted May 26, 2009 Posted May 26, 2009 So, just to clarify, am I right to say this is linear? As the "cons" has not been evaluated before the "recursion"? Quote
David Bethel Posted May 27, 2009 Posted May 27, 2009 In DOS days, you had to control stack and heap values in accordance to how much RAM your machine had. Today Windows allocates its as it can. -David http://www.computing.net/answers/programming/waht-is-stack-amp-heap/6345.html Quote
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.