help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Defining functions on the fly


From: Andreas Röhler
Subject: Re: Defining functions on the fly
Date: Tue, 16 Jun 2015 07:47:13 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0


Am 16.06.2015 um 01:51 schrieb Gene:
On Monday, June 15, 2015 at 5:24:40 AM UTC-4, Andreas Röhler wrote:
Hi,

have a bunch of subroutines which are useful in several modes -
beginning/end of expressions, string positions, comments etc.

Now every mode should get its own prefix.
Can't write

(defun (concat "current-prefix-" foo) ())

as defun expects a symbol.

Exists "fset" - is there a recommended way to go?
I recommend using lambda to experimentally develop what you think of as a 
function of the sort defun is typically used typically used to define.

Once the function's actual definition is done via lambda it can be bound to a 
symbol via fset

(fset (function name-of-function)
  (lambda (arg)
   "docstring"
   ; Body goes here
  )
)

Of course the anonymous version of the function can be used via higher order 
functions such as `apply' and `mapcar' so function development and testing can 
be furthered before one gets around to deciding to keep it around and name it 
for convenient future use.

This strategy is pretty much applicable in Scheme as well

(define name-of-function
  (lambda (arg)
   ;body
  )
)

I hope this helps.

Gene


It does, thanks!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]