all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Metaprogramming
@ 2019-09-15  3:13 Shyam Nath
  2019-09-15  7:32 ` Metaprogramming Teemu Likonen
  2019-09-15 13:22 ` Metaprogramming Stefan Monnier
  0 siblings, 2 replies; 6+ messages in thread
From: Shyam Nath @ 2019-09-15  3:13 UTC (permalink / raw)
  To: help-gnu-emacs

🖖 Hello World,



This is a  query from over half a decade ago: https://stackoverflow.com/q/22224045



I want to redefine functions by manipulating the pre-existing function; is there any way to do this?



I'd rather not just copy the whole function definition into my init.el file just to change one LOC; maybe there's a better way of doing this part instead?



LIVE LONG AND PROSPER \V/,
AGENT S.
🕴
Migrating Infestive Bugs !!


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

* Re: Metaprogramming
  2019-09-15  3:13 Metaprogramming Shyam Nath
@ 2019-09-15  7:32 ` Teemu Likonen
  2019-09-15  9:39   ` Metaprogramming Shyam Nath
  2019-09-15 13:22 ` Metaprogramming Stefan Monnier
  1 sibling, 1 reply; 6+ messages in thread
From: Teemu Likonen @ 2019-09-15  7:32 UTC (permalink / raw)
  To: Shyam Nath, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 930 bytes --]

Shyam Nath [2019-09-15T13:13:09+10] wrote:

> I want to redefine functions by manipulating the pre-existing
> function; is there any way to do this?

You can keep the original function code in a variable. Use that variable
to define the global function first and later all modified versions of
it.


    (defvar function-code (lambda (...) ...))
    
    (setf (symbol-function 'modifiable-function) function-code)


I think it is better to keep your defuns static and make them call
other functions which are stored in a variable or other predefined
place.


    (defvar modifiable-function (lambda (...) ...))

    (defun static-function (...)
      ;; ...
      (funcall modifiable-function ...)
      ;; ...
      )

-- 
///  OpenPGP key: 4E1055DC84E9DFF613D78557719D69D324539450
//  https://keys.openpgp.org/search?q=tlikonen@iki.fi
/  https://keybase.io/tlikonen  https://github.com/tlikonen

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 694 bytes --]

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

* Re: Metaprogramming
  2019-09-15  7:32 ` Metaprogramming Teemu Likonen
@ 2019-09-15  9:39   ` Shyam Nath
  0 siblings, 0 replies; 6+ messages in thread
From: Shyam Nath @ 2019-09-15  9:39 UTC (permalink / raw)
  To: Teemu Likonen; +Cc: help-gnu-emacs

🖖 Hello Teemu,



I am doing the 2ⁿᵈ option: https://stackoverflow.com/a/15725437



How can I access functions before they load?



LIVE LONG AND PROSPER \V/,
AGENT S.
🕴
Migrating Infestive Bugs !!



---- On Sun, 15 Sep 2019 17:32:59 +1000 Teemu Likonen <tlikonen@iki.fi> wrote ----


Shyam Nath [2019-09-15T13:13:09+10] wrote: 
 
> I want to redefine functions by manipulating the pre-existing 
> function; is there any way to do this? 
 
You can keep the original function code in a variable. Use that variable 
to define the global function first and later all modified versions of 
it. 
 
 
 (defvar function-code (lambda (...) ...)) 
 
 (setf (symbol-function 'modifiable-function) function-code) 
 
 
I think it is better to keep your defuns static and make them call 
other functions which are stored in a variable or other predefined 
place. 
 
 
 (defvar modifiable-function (lambda (...) ...)) 
 
 (defun static-function (...) 
 ;; ... 
 (funcall modifiable-function ...) 
 ;; ... 
 ) 
 
-- 
///  OpenPGP key: 4E1055DC84E9DFF613D78557719D69D324539450 
// https://keys.openpgp.org/search?q=tlikonen@iki.fi 
/ https://keybase.io/tlikonen https://github.com/tlikonen


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

* Re: Metaprogramming
  2019-09-15  3:13 Metaprogramming Shyam Nath
  2019-09-15  7:32 ` Metaprogramming Teemu Likonen
@ 2019-09-15 13:22 ` Stefan Monnier
  2019-09-15 14:36   ` Metaprogramming Stefan Monnier
  2019-09-15 19:03   ` Metaprogramming Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 2 replies; 6+ messages in thread
From: Stefan Monnier @ 2019-09-15 13:22 UTC (permalink / raw)
  To: help-gnu-emacs

> This is a  query from over half a decade ago: https://stackoverflow.com/q/22224045

That's not exactly about meta-programming, but rather about a peliminary
step you may (or may not) need for some meta-programming tasks.

> I want to redefine functions by manipulating the pre-existing
> function; is there any way to do this?

Yes, of course.  For example `advice-add` lets you do that.

> I'd rather not just copy the whole function definition into my init.el file
> just to change one LOC;
> maybe there's a better way of doing this part instead?

Then it depends on the specifics:
- what line of code?
- is the function usually compiled?
- is the source code available?
- is there a way to get that result differently?


        Stefan




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

* Re: Metaprogramming
  2019-09-15 13:22 ` Metaprogramming Stefan Monnier
@ 2019-09-15 14:36   ` Stefan Monnier
  2019-09-15 19:03   ` Metaprogramming Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2019-09-15 14:36 UTC (permalink / raw)
  To: help-gnu-emacs

> Then it depends on the specifics:
> - what line of code?
> - is the function usually compiled?
> - is the source code available?
> - is there a way to get that result differently?

BTW, you may want to look at `el-patch`.


        Stefan




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

* Re: Metaprogramming
  2019-09-15 13:22 ` Metaprogramming Stefan Monnier
  2019-09-15 14:36   ` Metaprogramming Stefan Monnier
@ 2019-09-15 19:03   ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2019-09-15 19:03 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier wrote:

>> This is a query from over half a decade ago:
>> https://stackoverflow.com/q/22224045
>
> That's not exactly about meta-programming [...]

"Metaprogramming is a programming technique in
 which computer programs have the ability to
 treat other programs as their data. It means
 that a program can be designed to read,
 generate, analyze or transform other programs,
 and even modify itself while running." [1]

One should probably have a good, or at least
explicit reason to do any of that, since
otherwise it'll just make things complicated
where they don't have to be. However if one
finds such a use case and pulls it off, that's
programming at the next level, no doubt.


[1] https://en.wikipedia.org/wiki/Metaprogramming

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

end of thread, other threads:[~2019-09-15 19:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-15  3:13 Metaprogramming Shyam Nath
2019-09-15  7:32 ` Metaprogramming Teemu Likonen
2019-09-15  9:39   ` Metaprogramming Shyam Nath
2019-09-15 13:22 ` Metaprogramming Stefan Monnier
2019-09-15 14:36   ` Metaprogramming Stefan Monnier
2019-09-15 19:03   ` Metaprogramming Emanuel Berg via Users list for the GNU Emacs text editor

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.