Help translate c+ => lisp!?

Discussion of Common Lisp

Help translate c+ => lisp!?

Postby georg » Fri Nov 11, 2011 10:52 am

Hi,

I am a newcomer can anywhere translate this to lisp?

cin<<x;

for( i = 0; i < x; i++) {

}

Thx..
Georg#
georg
 
Posts: 3
Joined: Fri Nov 11, 2011 10:24 am

Re: Help translate c+ => lisp!?

Postby nuntius » Fri Nov 11, 2011 8:43 pm

Adding in types, the C++ is probably
Code: Select all
int x;
cin >> x;
for(int i=0; i<x; i++) { ... }


Here's roughly equivalent CL.
Code: Select all
(let ((x (read *standard-input*)))
  (assert (integerp x))
  (dotimes (i x) ...))


There a few options for checking that x is an integer (such as an IF instead of the assert), there are times to prefer DO or LOOP over DOTIMES, and *STANDARD-INPUT* is a default and doesn't need to be specified to READ.
Please check out some of the books in the FAQ for this forum.
User avatar
nuntius
 
Posts: 497
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: Help translate c+ => lisp!?

Postby georg » Sat Nov 12, 2011 2:05 am

Thx for you reply!

still I have a problem whit the ACAD lisp

me lisp doesn't not work...

(print)

(defun C:PL ()
(setvar "OSMODE" 1)
(INITGET 1)
(setq P1 (getpoint "\n Lower Left Endpoint: "))
(INITGET 1)
(setq P2 (getpoint "\n Upper Right Endpoint: "))
(setvar "OSMODE" 0)
;;***********************************************

(print "How many copies?")

(let ((x (read *standard-input*)))
(assert (integerp x))
(dotimes (i x)
;************************************************* **************************************************
(setvar "cmdecho" 0)
(command "-PLOT" "j" "" "Canon MP270 series Printer" "A4" "" "" "" "fe" P1 P2 "" "" "" "acad.ctb" "" "" "" "" "" "" "")
))


;************************************************* **************************************************
)
georg
 
Posts: 3
Joined: Fri Nov 11, 2011 10:24 am

Re: Help translate c+ => lisp!?

Postby nuntius » Sat Nov 12, 2011 11:07 am

Are we talking Common Lisp or Autolisp (used by AutoCad) or something else?
What program reads the files?
User avatar
nuntius
 
Posts: 497
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: Help translate c+ => lisp!?

Postby georg » Sat Nov 12, 2011 12:08 pm

The prog. is for Acad! Is there a difference?
georg
 
Posts: 3
Joined: Fri Nov 11, 2011 10:24 am

Re: Help translate c+ => lisp!?

Postby Indecipherable » Sun Nov 13, 2011 1:21 am

georg wrote:The prog. is for Acad! Is there a difference?

Well, it is another Lisp dialect, so I presume there is.
Don't take the FUN out of DEFUN !
User avatar
Indecipherable
 
Posts: 47
Joined: Fri Jun 03, 2011 5:30 am
Location: Behind you.


Return to Common Lisp

Who is online

Users browsing this forum: joeish80829 and 1 guest

cron