Jump to content

Recommended Posts

Posted

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

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    7

  • Se7en

    6

  • The Buzzard

    3

  • john_

    3

Top Posters In This Topic

Posted

Hi and thanks

How do I get a moderator to move it?

Posted

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.

Posted

John,

 

I sent a message for you, Please give it a little time.

Posted

I believe it would be easier if it were a word document and not your basic .txt file. I may be wrong.

Posted

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")
)

Posted

I love that "pars" function - I saw it used at the Swamp a few times - Elpanov is a genius :D

 

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... :huh:

Posted
I love that "pars" function - I saw it used at the Swamp a few times - Elpanov is a genius :D

 

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... :huh:

 

`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.

Posted
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...

Posted

*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.

Posted

This is a very old routine by Duff Kirkland ( modified to accept all file type extensions ) -David

DDTYPE.DCL

DDTYPE.LSP

Posted
*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... :unsure:

Posted

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.

Posted

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... :unsure:

Posted

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))) )

Posted
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... :cry:

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...