Author Topic: Just for fun...functions to eval items from a list of defuns (or somesuchthing)  (Read 2707 times)

0 Members and 1 Guest are viewing this topic.

uncoolperson

  • Guest
this 'kinda works', haven't been able to narrow down the problem, seems to pass arguements 'okay' however i keep ending up with an error about no function 0.6798 or some such thing when i try to incorporate all my defuns.

I've been throwing everything into lists to get a better look at stuff, i know it's not necessary.

again this is just for fun... :ugly:

Code: [Select]


(setq biglist
       '((defun bigtest ( something)
  (alert something))))


(DEFUN loadfun (thefunction)
  (FOREACH funct biglist
    (IF (= 'DEFUN (NTH 0 funct))
      (IF (= thefunction (VL-SYMBOL-NAME (NTH 1 funct)))
  (eval funct)
      )
    )
  )
)


(foreach item (setq newlist (MAPCAR '(LAMBDA (funct)
     (IF (= 'DEFUN (NTH 0 funct))
       (LIST (NTH 0 funct)
     (NTH 1 funct)
     (NTH 2 funct)
     (LIST 'loadfun
   (VL-SYMBOL-NAME (NTH 1 funct)))
   (IF (NTH 2 funct)
     (LIST 'EVAL
   (append (LIST (NTH 1 funct))
   (if (member '/ (NTH 2 funct))
(reverse(cdr (member '/ (reverse (NTH 2 funct)))))
     (NTH 2 funct))
   )
     )
     (LIST 'EVAL (LIST (NTH 1 funct)))
   )
     )
       funct
     )
   )
biglist
))
  (eval item))

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Not sure I follow you but give this a whirl and see if it provides any fun for ya. (granted this is done on princple only.)

Code: [Select]
(setq lst
     '((alert "This is alert no 1")
      (princ "\nthis is prompt 1")
      (alert "This is alert no 2")
      (princ "\n\nThis is prompt no 2")) )

(defun hook-n-do (lst)
  (if (not (null lst))
    (progn
      (eval (list (cons 'lambda (cons nil (list (car lst))))))
      (hook-n-do (cdr lst))))
  (princ) )

*Edit: Sorry should have ran it first; The list was wrong.
« Last Edit: November 07, 2005, 12:17:51 PM by Se7en »
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

uncoolperson

  • Guest
i'm trying to make an AUTOLOADish type thing (for what purpose... well i explained that already, just to explore)

so i put
Code: [Select]
(setq biglist '(
at the begining of my original acad.lsp file

and this
Code: [Select]
))

at the end

and throw the rest of the code somewhere else so it actually gets loaded.


then that foreach creates a function of the same name that evals the original defun statement...


JohnK

  • Administrator
  • Seagull
  • Posts: 10651
*blink* ...WHhhAT?!  *lol*

So as far as i can tell you rebuild the original using the same name with your 'foreach' statement. (I know this is all for fun but...) Why? (I too appreciate the fun in code, but) Why rebuild it. Why not eval it if all you want is a ''loader'' of sorts.

Why not store the original in some other format then ASCII text. use an encoded/decoded method or something (use 8 letters of the alphabet instead of just leaving it text or something.)

*lol*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

uncoolperson

  • Guest
yeah i know it's not even close to purposeful...(maybe alittle retarded) i just want to see if it can.  :oops:

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Man i have TONS of un-usefull code! I also think its alot of fun to just goof arround with code.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

uncoolperson

  • Guest
I have one of these about halfway down every lisp file

Code: [Select]
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ***********************************************************************************************;;
;; *;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*;;
;; *;;;/-------------------------------------------------------------------------------------\;;;*;;
;; *;;;|  Old/Retarded stuff below, kept for reference only... mostly obsolete or unusable.  |;;;*;;
;; *;;;\-------------------------------------------------------------------------------------/;;;*;;
;; *;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*;;
;; ***********************************************************************************************;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;