all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Question about Elisp language abilities (evaluating expr on time of func definition and ability to construct function).
@ 2011-09-29 21:33 Oleksandr Gavenko
  2011-09-29 22:14 ` Oleksandr Gavenko
  0 siblings, 1 reply; 3+ messages in thread
From: Oleksandr Gavenko @ 2011-09-29 21:33 UTC (permalink / raw)
  To: help-gnu-emacs

I learn Elisp lang capability. According to

   13.2 Expansion of a Macro Call

section of 'info elisp':

      Evaluation of the macro call begins like evaluation of a
   function call except for one crucial difference: the macro
   arguments are the actual expressions appearing in the macro
   call. They are not evaluated before they are given to the
   macro definition.

So Elisp macro executed when func called, but with different algorithm
of args passing. This allow make "new" language constructions but
I know about more powerful abilities.


Is there any Elisp special form which evaluate args when 'defun' parsed
(like words which defined with IMMEDIATE marker in Forth prog lang)?

In Forth in time of processing of word definition compiler can pass
control to interpreter when encounter special word until they decide
back to compilation process.

So in similar construction exist in Elisp this hypothetical code:

   (defun f (x)
      (IMMEDIATE (message "hello!"))
      (1+ x)
     )

on 'f' compilation stage print "hello" and never do this on 'f'
evaluation.


Another question is there ability to construct function on the fly.
For example:

   (GENFUNC get-parser (syntax-tree) (data)
      ...
     )

syntax-tree is a string, data is free argument. When you call

   (get-parser "a=a|ab; b=*")

you get function with one argument (remember 'data'?) which constructed
dynamically and can perform parsing very speedily
(as 'get-parser' can be more fast then general purpose parser
as it know 'syntax-tree' on construction stage).




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about Elisp language abilities (evaluating expr on time of func definition and ability to construct function).
  2011-09-29 21:33 Question about Elisp language abilities (evaluating expr on time of func definition and ability to construct function) Oleksandr Gavenko
@ 2011-09-29 22:14 ` Oleksandr Gavenko
  2011-09-29 22:45   ` Oleksandr Gavenko
  0 siblings, 1 reply; 3+ messages in thread
From: Oleksandr Gavenko @ 2011-09-29 22:14 UTC (permalink / raw)
  To: help-gnu-emacs

30.09.2011 0:33, Oleksandr Gavenko пишет:
> I learn Elisp lang capability. According to
>
> 13.2 Expansion of a Macro Call
>
> section of 'info elisp':
>
> Evaluation of the macro call begins like evaluation of a
> function call except for one crucial difference: the macro
> arguments are the actual expressions appearing in the macro
> call. They are not evaluated before they are given to the
> macro definition.
>
> So Elisp macro executed when func called, but with different algorithm
> of args passing. This allow make "new" language constructions but
> I know about more powerful abilities.
>
>
> Is there any Elisp special form which evaluate args when 'defun' parsed
> (like words which defined with IMMEDIATE marker in Forth prog lang)?
>
> In Forth in time of processing of word definition compiler can pass
> control to interpreter when encounter special word until they decide
> back to compilation process.
>
> So in similar construction exist in Elisp this hypothetical code:
>
> (defun f (x)
> (IMMEDIATE (message "hello!"))
> (1+ x)
> )
>
> on 'f' compilation stage print "hello" and never do this on 'f'
> evaluation.
>
>
> Another question is there ability to construct function on the fly.
> For example:
>
> (GENFUNC get-parser (syntax-tree) (data)
> ...
> )
>
> syntax-tree is a string, data is free argument. When you call
>
> (get-parser "a=a|ab; b=*")
>
> you get function with one argument (remember 'data'?) which constructed
> dynamically and can perform parsing very speedily
> (as 'get-parser' can be more fast then general purpose parser
> as it know 'syntax-tree' on construction stage).
>
When write previous post I use '(when (x-condp) (defun f (x) x))'
expression.

And recall as I wrote such code half year before to avoid
code duplication in .emacs:

   (defmacro my-defun-rename-symb-tree (name doc func)
     "Travel by TREE and applies FUNC to each symbol."
     `(defun ,name (tree)
        ,doc
        (cond
         ((symbolp tree)
          (,func tree)
          )
         ((listp tree)
          (mapcar ',name tree)
          )
         (t (error "Only tree of symbols allowed."))
         )))

   (my-defun-rename-symb-tree
    my-feature2mode
    "Convert TREE of features to TREE of modes for these features.
   Single symbol allowed."
    (lambda (symb) (intern (concat (symbol-name symb) "-mode"))))

   (my-defun-rename-symb-tree
    my-mode2hook
    "Convert TREE of modes to TREE of hooks for these modes.
   Single symbol allowed."
    (lambda (symb) (intern (concat (symbol-name symb) "-hook")))
    )

So from:

   (defvar my-devel-mode-list '(sh-mode script-mode tcl-mode
     c-mode c++-mode java-mode js-mode))

I can get:

   (defvar my-devel-mode-hook-list (my-mode2hook my-devel-mode-list))

So my both question positively answered.


How about nested defmacro? As you see after evaluating macro interpreter
can create function (by 'defun'). What if defmacro create defmacro?




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about Elisp language abilities (evaluating expr on time of func definition and ability to construct function).
  2011-09-29 22:14 ` Oleksandr Gavenko
@ 2011-09-29 22:45   ` Oleksandr Gavenko
  0 siblings, 0 replies; 3+ messages in thread
From: Oleksandr Gavenko @ 2011-09-29 22:45 UTC (permalink / raw)
  To: help-gnu-emacs

30.09.2011 1:14, Oleksandr Gavenko пишет:
> 30.09.2011 0:33, Oleksandr Gavenko пишет:
>> Is there any Elisp special form which evaluate args when 'defun' parsed
>> (like words which defined with IMMEDIATE marker in Forth prog lang)?
>>
>> (defun f (x)
>> (IMMEDIATE (message "hello!"))
>> (1+ x)
>> )
>>

I have understood that difference between Elisp and Forth
syntax (on evaluation)!

In Forth word definition IMMEDIATE like word placed into definition:

   : abs dup <0 if neg then ;

'if' and 'then' such word. On other corner in Elisp you wrap
whole definition with powerful macro construction:

 > (defmacro my-defun-rename-symb-tree (name doc func)
 > "Travel by TREE and applies FUNC to each symbol."
 > `(defun ,name (tree)




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-09-29 22:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-29 21:33 Question about Elisp language abilities (evaluating expr on time of func definition and ability to construct function) Oleksandr Gavenko
2011-09-29 22:14 ` Oleksandr Gavenko
2011-09-29 22:45   ` Oleksandr Gavenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.