Jump to content

Pass Variables by Reference


ignarous

Recommended Posts

For example, consider the following function to increment the value of a variable passed by reference:

(defun ++ ( sym )
   (set sym (1+ (eval sym)))
)

_$ (setq x 1)
1
_$ x
1
_$ (++ 'x)
2
_$ x
2

Link to comment
Share on other sites

Thank you very much dear lee mac, you light up the darkness in which I was

Applying the above, I get it. But in another case, he omits it. Attached LISP code, please signal me the error

 

 

(defun c:SUMANGDMS () ; Sumatoria Angular RAD a DMS, redondeo al segundo

 

; ----------------------------------------------------------------------

; funcion Lambda q redondea num_real a un # especifico de decimales, num_dec

; call (round numReal numDec)

 

(setq round (lambda (num_real num_dec) (/ (fix (+ (* num_real (setq num_dec (expt 10. num_dec))) (if (minusp num_real) -0.5 0.5)) ) num_dec )))

 

; ----------------------------------------------------------------------

; funcion (valores por referencia) enteros y fracciones, multiplos de 60

; call (Fsixty a b 'a 'b)

(defun Fsixty (nm1 nm2 pointer1 pointer2 / nm1 nm2)

(set pointer1 (eval (+ nm1 (fix (/ nm2 60.0)))))

(set pointer2 (eval (rem nm2 60.0)))

) ; FIN (defun Fsixty (nm1 nm2 pointer1 pointer2)

 

; ----------------------------------------------------------------------

; funcion RAD to DMS ; Como Numero

(defun Fgms_num ( angulo_rad / grados minutos segundos )

; Convierte RAD a DEC

(setq angulo_dec (* (/ 180 pi) angulo_rad))

 

; Convirtiendo DEC a DMS

(setq grados (fix angulo_dec)) ; grados

(setq minutos (* (- angulo_dec grados) 60))

(setq segundos (* (- minutos (fix minutos)) 60)) ; segundos

(setq minutos (fix minutos)) ; minutos

 

 

; Segundos a Minutos, multiplos de 60

(if (> segundos 59)

(Fsixty minutos segundos 'minutos 'segundos)

)

 

; Minutos a Grados, multiplos de 60

(if (> minutos 59)

(Fsixty grados minutos 'grados 'minutos)

)

 

; Construccion Lista global (degree minutes and seconds)

(setq *Ldms* nil)

(setq *Ldms* (list grados minutos (round segundos 0)))

(print) (princ *Ldms*) (print)

) ; FIN (defun Fgms_num ( angulo_rad / grados minutos segundos mm )

 

; ======== MAIN PROGRAM =============================

; (setq v1 (Fgms_num 0.2707442)) ; 15°30'45"

; (setq v2 (Fgms_num 0.7999668)) ; 45°50'05"

; (setq v3 (Fgms_num 2.3826653)) ; 136°31'00"

; (setq v4 (Fgms_num 3.7750017)) ; 216°17'30"

; (setq v5 (Fgms_num 5.8827050)) ; 337°03'15"

 

; Inicializacion

(setq Ldms nil i1 0 sum_grd 0 sum_min 0 sum_seg 0)

(setq angulos_rad (list 0.2707442 0.7999668 2.3826653 3.7750017 5.8827050))

 

(while (

(progn

; Call function DMS Number

(Fgms_num (nth i1 angulos_rad))

; Sum degree, minutes y seconds

(setq sum_grd (+ (car *Ldms*) sum_grd))

(setq sum_min (+ (cadr *Ldms*) sum_min))

(setq sum_seg (+ (caddr *Ldms*) sum_seg))

(setq i1 (1+ i1))

)

) ; FIN while

 

; Segundos a Minutos, multiplos de 60

(if (> sum_seg 59) (Fsixty sum_min sum_seg 'sum_min 'sum_seg) )

 

; Minutos a Grados, multiplos de 60

(if (> sum_min 59) (Fsixty sum_grd sum_min 'sum_grd 'sum_min) )

 

; Asignacion a Lista

(setq sumatoria (list sum_grd sum_min sum_seg))

; Impresion de Valores

(print) (princ sumatoria) (print)

 

) ; FIN (defun c:SUMANGDMS () ; Sumatoria Angular RAD a DMS

 

; Muestra al Usuario, Nombre de Funcion

(prompt "Suma Angulos declarados, tipear SUMANGDMS")

 

 

RUN

 

(15 30 45.0) good

(45 50 5.0) good

 

(136 30 60.0) bad (136 31 0)

 

(216 17 30.0) good

(337 3 15.0) good

 

(751 12.0 35.0) GOOD

Link to comment
Share on other sites

  • 2 weeks later...

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