Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ challenge

Name: Anonymous 2014-07-16 18:35

Write a macro that, given a term of code, transforms all the calls to the function FOO in that term, and only those calls, into calls to function BAR with the same arguments.
Language: Common Lisp or Scheme.

Name: Anonymous 2014-07-18 10:56

>>40
I think a reasonable definition for Common Lisp would be (funcall (function foo) ...) (foo ...) and maybe even (apply (function foo) ...).

That's what I took OP's challenge to mean.

Name: Anonymous 2014-07-18 13:07

>>41
What about this:
(funcall (function (intern "foo")))
Please provide a formal definition.

Name: Anonymous 2014-07-18 19:23

>>32
Does not work:

* (foo->bar `(foo 7))
(FOO 7)

Name: Anonymous 2014-07-18 19:34

>>30
He is not correct. A call to macro zoo is not a call to function foo. The challenge is to transform just the direct calls to a function, without interfering with the inner workings of any functions or macros (it's called "information hiding"). Besides, once you can target exclusively the direct calls, it would be trivial to call macroexpand first and then to call our macro.

Name: Anonymous 2014-07-18 19:37

>>36
I can only hope that function calls are better defined in Scheme. Common Lisp, it seems, is totally unsuitable for writing code transforms.

Name: Anonymous 2014-07-18 19:46

Oops, sorry, Scheme has

((eval (string->symbol "foo")) arg1 arg2 ...)

Therefore, my challenge has no solutions in either CL or Scheme.

Name: Anonymous 2014-07-18 19:56

>>36
trolled us all by posting an ill-imposed problem.

Not at all. I was just trying to find out if s-exp languages have any actual advantages for writing macros. Lispers talk much about how cool "code is data" is, and how much easier writing macros is with s-exps. Yet it seemed to me that most of their macros are generative, which the s-exps are not particularly advantageous for (it can be done in any "blub" language, just look at Nemerle or Rust or Metalua, for example). So I wondered if homoiconicity is good for transformative macros. And it turns out that you can't even write a reliable function-swapping macro with it. At least with the s-exp kind of homoiconicity.

Name: Anonymous 2014-07-18 20:35

Write a function-swapping macro for forth.

Name: Anonymous 2014-07-18 21:46

>>47
What does Lisp have to do with s-expressions?

s-expressions are a text syntax for Lisp.

Macros don't transform s-expressions, they transform Lisp forms.

The compiler and macro-expander work on Lisp forms, not on s-expressions.

Name: Anonymous 2014-07-18 21:56

>>46

It has a solution, and it's a new evaluator.

If >>9 handled all special forms (and also replaced all calls to eval to itself) you'd get what you want.

Name: Anonymous 2014-07-18 23:20

>>44
It's arbitrary if you want the replacement to work on expanded inner macros or not. You can either call macro expand before doing the deep substitution or not call macro expand. I don't know what your use case is in using this macro, but if you want to preserve referential transparency the inner macros must be expanded first.

>>47
You can. But I wont. Do your own research you cock sucking faggot.

>>49
Macros take unevaluated lisp forms as input, which are s-expressions.

Name: Anonymous 2014-07-18 23:32

>>51
Unevaluated Lisp forms are not s-expressions!

S-expressions are text, made up of characters. Lisp forms are Lisp objects.

s-expression → Lisp reader that understands s-expressions → Lisp form

Name: Anonymous 2014-07-18 23:32

>>44
Furthermore, you cock sucking faggot, unevaluated lisp with no expanded macros may consist of forms outside the lisp spec. Lisp macros allow you to define entirely different languages and a macro that attempts to locate all function calls will not be able to do the traversal without being extended for each macro written. Thus the only way the macro can work as intended is to expand the inner macros, thereby translating all nested DSLs to lisp, and then performing the code transformation on code containing nothing other than lisp forms defined in the spec.

Name: Anonymous 2014-07-19 3:14

No seriously, I don't think you people even understand this. I need a formal definition before I present a solution. Consider:
(funcall (function (intern (read))))
Do we want BAR to be called when FOO is entered by the user?

Name: Anonymous 2014-07-19 18:20

>>53
What if you need to locate all calls to a particular macro? They won't even exist after macroexpansion.

Name: Anonymous 2014-07-19 19:49

>>55
that's why you can alter the readtable and how the lisp REPL works from within CL. But FFS: You usually DON'T want to mess with macros.

Name: Anonymous 2014-07-19 19:57

>>52
No, s-expressions are trees i.e. XML.

Name: Anonymous 2014-07-19 21:24

>>57
XML has attributes, it's not just a pure tree representation

Name: Anonymous 2014-07-19 22:11

>>57
XML is text. XML and s-expressions are text which conforms to a certain textual syntax.

Name: Anonymous 2014-07-19 22:29

Basically OP, try doing your request using your language of choice. You will see the problem is not the language, but the request itself. Symbolic expressions are just that, expressions notated in a tree like fashion:
https://en.wikipedia.org/wiki/Symbolic_expressions

It has nothing to do with the ability to of the programmers here to rewrite a new interpreter. You are welcome to prove Lisp users otherwise.

Name: Anonymous 2014-07-20 7:21

>>55
Search the tree and as you search expand macros. Keep going down the tree until you find the macro you are looking for or you hit the bottom. The call to the macro could occur within an expanded macro at some arbitrary level.

Name: Anonymous 2014-07-20 16:15

>>59
Text is binary.

Name: Anonymous 2014-07-20 16:45

serialise my anus

Name: Anonymous 2014-07-21 11:29

>>63
serialize my anus

Name: Anonymous 2014-07-21 12:10

serialize my anuz.

Name: Anonymous 2014-07-21 13:32

zerialize my anuz

Name: Anonymous 2014-07-21 20:02

>>34
>>35

(funcall #'foo)
isn't a call to foo in the same sense as (foo). It's a call to whatever foo's function slot is bound to at runtime.

Name: Anonymous 2014-07-21 20:03

>>43

'(foo 7)
isn't a call to foo, it's a list of 'foo and 7.

Name: Anonymous 2014-07-22 7:09

>>67
Thanks for clarifying that. I just couldn't remember the term 'function slot', and what the difference between (foo) and (funcall 'foo) is, if any. The solution posted above then is complete and correct.

>>68
He didn't know how use macros obviously.

Name: Anonymous 2014-07-25 1:41

why are you fucks so obsessed with this metaprogramming bullshit

Name: Anonymous 2014-07-25 1:49

>>70
Go back to your 4chan and go back to your facebook and go back to your dawkins.

Name: Anonymous 2014-07-25 5:01

>>71
Go back to mother russia

Name: Anonymous 2014-07-26 11:27

>>68
It's a term of code that contains a call to function foo. You're a fucking retard who cannot read.
>>69
You're a fucking retard who has never used Lisp macros, obviously.

Name: Anonymous 2014-07-26 16:54

>>72

Go back to le Republique

Name: Anonymous 2014-07-27 16:01

>>73
(list 'foo 7)
>'(foo 7)

It's only a function call when you tell lisp to evaluate it. Since that hasn't happened, it's just a list.

Is '(7 7) a function call to the number 7?

Name: Anonymous 2014-07-27 16:30

>>75
A term of code. A term of code. How many times do I have to repeat it till it sinks? There is a difference between a term of code and the process of its evaluation. Macros work specifically on terms of code.

Name: Anonymous 2014-07-27 16:36

>>76
Macros are passed unevaluated forms yes. But the unevaluated form of '(foo 7) is doubly unevaluated so it still doesn't make sense.

Name: Anonymous 2014-07-27 16:37

>>76
What makes '(7 7) different from '(foo 7) ?
And please define 'term of code'. I'm not sure what you mean.

Name: Anonymous 2014-07-27 16:43

Here you go
http://bit.ly/WIWHQO

macro FOO {
rule { ($param ...) } => { BAR($param ...) }
}


FOO(); // BAR();
function f() {
FOO(1, 2, 'hax my anus', FOO(3)); // BAR(1, 2, 'hax my anus', BAR(3);
}

Name: Anonymous 2014-07-27 16:56

>>77,78
Whatever I don't have time to learn Lisp.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List