Replies: 1 comment 3 replies
-
Code generation is good (both on-line [just before or during runtime] and off-line [before runtime]), self-modifying code (in memory) is also good, but I don't know what to say about program that modifies it's own source code text – sounds like something very fragile. I usually don't even like when programs modify their config files, let alone source code. Maybe I haven't reached zen of programming like Ian Henry. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I (not an Emacs user) was inspired by this:
“I want to tell you about an idea that has had a huge influence on the way that I write software. And I mean that in the literal sense: it’s changed the way that I write software; it’s re-shaped my development workflow.
The idea is this: you can write programs that modify themselves.
And I don’t mean macros or metaprogramming or anything fancy like that. I mean that you can write programs that edit their own source code. Like, the files themselves. The actual text files on disk that have your source code in them.
That’s not the whole idea, though. There’s more to it: you write programs that can edit themselves, and then you use that as your REPL.”
Ian Henry: My Kind of REPL, 2023: https://ianthehenry.com/posts/my-kind-of-repl/
This is a fragment from my loaded/consulted file, say,
stranka-slovo.pl
:Then, after this imperative query (
selfSave/0
is imported):my source file
stranka-slovo.pl
, the fragment, looks like this:Or, with this fragment:
the new, modified source file will have:
This is my first, experimental, very quick and dirty prototype of the imported file
self-edit.pl
:So far, so good; and I was thinking, everything is so simple in Prolog...
But then, I was thinking: Wait a minute, I don't want name clashes, I need a real module...
If I add this line to my
self-edit.pl
file/module::- module('self-edit',[selfPrint/0, selfSave/0]).
I get this:
It seems reasonable: an attempt to call the predicate
reportOdkazy/1
in the imported module, but the predicate is not defined in the module.Yes, I'm a naive user, crazy ideas etc.: is it possible, in Scryer, to have a proper/isolated module imported and yet from that module to call a predicate with the "environment/context" of an importing file? And I mean simplicity of:
%? reportOdkazy(Ls).
?- selfSave.
Or, now I "have two problems"?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions