Author Topic: Newbie Question ..  (Read 9011 times)

0 Members and 1 Guest are viewing this topic.

RobbeK

  • Guest
Re: Newbie Question ..
« Reply #30 on: June 16, 2014, 06:32:35 AM »
Looking very interesting Charles --  the usual way (NewLisp syntax)

=================================



(define (mean L)
  (div (apply add L) (length L)))

(define (another-mean L)
  (div (eval (cons 'add L )) (lenght L)))

;;the usual way but bad examples --  + already is variadic , for non-variadic functions only the first element is processed and returned.

(define (meanO)
 (let ((m 0) (n 0))           ;; let defines the locals (parallel)  let*/letn sequential
  (doargs (i)
     (inc m i)
     (inc n))
 (div m n)))                   ;; result must be returned within the (let     ....  ) 
               
;;  (meanO 5 6 7) -> 6  :: using arg(i)   

(define (meanOO L)
  (apply meanO L))
;; works on a List now   (meanOO (list 5 6 7) )


;; by Iteration

(define (meanI L)
 (let ((m 0)  (n (length L)) )
  (dotimes (i n)
     (inc m (L i)) )
  (div m n)))

;; using the direct index i (0...n-1)   ::  in Common Lisp (L i) is written  (nth i L) 

(I use a wider font for Lisp  ::) than shown here ...     something as doargs could be very useful .
Common Lisp uses also &rest

(defun something (a b &rest r)  r )

(something '( 1 2 3 4 5)) -> (3 4 5)

Hi Mike,

" as if he had his front teeth knocked out."   ..  but, but , that's the greenhorn treatment at your first Lisp Congress, how did you know ??
 ;)

best Rob





Mike Lobanovsky

  • Guest
Re: Newbie Question ..
« Reply #31 on: June 16, 2014, 07:50:54 AM »
... that's the greenhorn treatment at your first Lisp Congress ...

Hehe,

The Lisp community is trying to live up to its name. :D