print arguments of function call without evaluation, not using “macro”





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















Arguments will be evaluated during a function call in Lisp. Is there any way besides macro to print the argument without evaluation?



Take an example in Common Lisp:



(defun foo (&rest forms)
(loop for i in forms collect i))


Call "foo" in REPL toplevel:



CL-USER> (foo (= 1 2) (< 2 3))


Got the result:



(NIL T)


Is there any way to get this result?:



((= 1 2) (< 2 3))









share|improve this question

























  • You'll almost certainly need a macro for that. The only exception I can think of is that the special variables *, /, and + let you special stiff in the REPL, like currently evaluating form. If you only need this in the REPL, you could use something with those.

    – Joshua Taylor
    Dec 24 '15 at 2:45











  • Thanks Joshua! I just want to confirm my understanding of function and macro. Actually I want the "code" to be the "data". That's what macro is good at.

    – jarod.tian
    Dec 24 '15 at 2:54


















2















Arguments will be evaluated during a function call in Lisp. Is there any way besides macro to print the argument without evaluation?



Take an example in Common Lisp:



(defun foo (&rest forms)
(loop for i in forms collect i))


Call "foo" in REPL toplevel:



CL-USER> (foo (= 1 2) (< 2 3))


Got the result:



(NIL T)


Is there any way to get this result?:



((= 1 2) (< 2 3))









share|improve this question

























  • You'll almost certainly need a macro for that. The only exception I can think of is that the special variables *, /, and + let you special stiff in the REPL, like currently evaluating form. If you only need this in the REPL, you could use something with those.

    – Joshua Taylor
    Dec 24 '15 at 2:45











  • Thanks Joshua! I just want to confirm my understanding of function and macro. Actually I want the "code" to be the "data". That's what macro is good at.

    – jarod.tian
    Dec 24 '15 at 2:54














2












2








2








Arguments will be evaluated during a function call in Lisp. Is there any way besides macro to print the argument without evaluation?



Take an example in Common Lisp:



(defun foo (&rest forms)
(loop for i in forms collect i))


Call "foo" in REPL toplevel:



CL-USER> (foo (= 1 2) (< 2 3))


Got the result:



(NIL T)


Is there any way to get this result?:



((= 1 2) (< 2 3))









share|improve this question
















Arguments will be evaluated during a function call in Lisp. Is there any way besides macro to print the argument without evaluation?



Take an example in Common Lisp:



(defun foo (&rest forms)
(loop for i in forms collect i))


Call "foo" in REPL toplevel:



CL-USER> (foo (= 1 2) (< 2 3))


Got the result:



(NIL T)


Is there any way to get this result?:



((= 1 2) (< 2 3))






scheme lisp common-lisp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 30 '15 at 10:51









Will Ness

46.9k469127




46.9k469127










asked Dec 24 '15 at 2:03









jarod.tianjarod.tian

165




165













  • You'll almost certainly need a macro for that. The only exception I can think of is that the special variables *, /, and + let you special stiff in the REPL, like currently evaluating form. If you only need this in the REPL, you could use something with those.

    – Joshua Taylor
    Dec 24 '15 at 2:45











  • Thanks Joshua! I just want to confirm my understanding of function and macro. Actually I want the "code" to be the "data". That's what macro is good at.

    – jarod.tian
    Dec 24 '15 at 2:54



















  • You'll almost certainly need a macro for that. The only exception I can think of is that the special variables *, /, and + let you special stiff in the REPL, like currently evaluating form. If you only need this in the REPL, you could use something with those.

    – Joshua Taylor
    Dec 24 '15 at 2:45











  • Thanks Joshua! I just want to confirm my understanding of function and macro. Actually I want the "code" to be the "data". That's what macro is good at.

    – jarod.tian
    Dec 24 '15 at 2:54

















You'll almost certainly need a macro for that. The only exception I can think of is that the special variables *, /, and + let you special stiff in the REPL, like currently evaluating form. If you only need this in the REPL, you could use something with those.

– Joshua Taylor
Dec 24 '15 at 2:45





You'll almost certainly need a macro for that. The only exception I can think of is that the special variables *, /, and + let you special stiff in the REPL, like currently evaluating form. If you only need this in the REPL, you could use something with those.

– Joshua Taylor
Dec 24 '15 at 2:45













Thanks Joshua! I just want to confirm my understanding of function and macro. Actually I want the "code" to be the "data". That's what macro is good at.

– jarod.tian
Dec 24 '15 at 2:54





Thanks Joshua! I just want to confirm my understanding of function and macro. Actually I want the "code" to be the "data". That's what macro is good at.

– jarod.tian
Dec 24 '15 at 2:54












2 Answers
2






active

oldest

votes


















8














You can’t do that in either Scheme or Common Lisp without macros. Of course, it’s also pretty trivial with macros, so feel free to use them if they fit your use case.



That said, there’s a bit more to this question than you may have anticipated. You’re effectively asking for a feature that was present in older Lisps that has fallen out of fashion, known as fexprs. A fexpr is exactly what you describe: a function whose operands are passed to it without being evaluated.



Most modern dialects have done away with fexprs in favor of only using macros, and you can see this Stack Overflow question for more information on why. The gist is that fexprs are hard to optimize, difficult to reason about, and generally less powerful than macros, so they were deemed both redundant and actively harmful and were summarily removed.



Some modern Lisps still support fexprs or something like them, but those dialects are rare and uncommon in comparison to the relative giants that are Scheme and CL, which dominate the modern Lisp world. If you need this sort of thing, just use macros. Better yet, just quote the arguments so you don’t need any macros at all. You’ll be more explicit (and therefore much clearer), and you’ll get the same behavior.






share|improve this answer


























  • As far as I remember, fexprs where an experimental side track in a few dialects, but never something you'd generally expect from a Lisp.

    – Svante
    Dec 25 '15 at 0:40











  • Thanks Alexis! Your answer opened my eye a lot. Actually I had this question when I was reading the book <practical common lisp>. I was thinking why I cannot use plain function rather than macro. That means why macro is necessary. So I tried to simulate macro's behaviour by writing the function "foo" in this question. Maybe I need more thinking about "macro" to fully understand it's secret. I will read the reference you quoted.

    – jarod.tian
    Dec 27 '15 at 2:28



















2














Yes; you can get the result with an operator called quote, if you don't mind one more level of nesting:



(quote ((= 1 2) (< 2 3)))
-> ((1 2) (2 3))


quote isn't a macro; it is a special operator.






share|improve this answer
























  • Thanks Kaz! It works without "macro".

    – jarod.tian
    Dec 27 '15 at 2:21












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34446324%2fprint-arguments-of-function-call-without-evaluation-not-using-macro%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









8














You can’t do that in either Scheme or Common Lisp without macros. Of course, it’s also pretty trivial with macros, so feel free to use them if they fit your use case.



That said, there’s a bit more to this question than you may have anticipated. You’re effectively asking for a feature that was present in older Lisps that has fallen out of fashion, known as fexprs. A fexpr is exactly what you describe: a function whose operands are passed to it without being evaluated.



Most modern dialects have done away with fexprs in favor of only using macros, and you can see this Stack Overflow question for more information on why. The gist is that fexprs are hard to optimize, difficult to reason about, and generally less powerful than macros, so they were deemed both redundant and actively harmful and were summarily removed.



Some modern Lisps still support fexprs or something like them, but those dialects are rare and uncommon in comparison to the relative giants that are Scheme and CL, which dominate the modern Lisp world. If you need this sort of thing, just use macros. Better yet, just quote the arguments so you don’t need any macros at all. You’ll be more explicit (and therefore much clearer), and you’ll get the same behavior.






share|improve this answer


























  • As far as I remember, fexprs where an experimental side track in a few dialects, but never something you'd generally expect from a Lisp.

    – Svante
    Dec 25 '15 at 0:40











  • Thanks Alexis! Your answer opened my eye a lot. Actually I had this question when I was reading the book <practical common lisp>. I was thinking why I cannot use plain function rather than macro. That means why macro is necessary. So I tried to simulate macro's behaviour by writing the function "foo" in this question. Maybe I need more thinking about "macro" to fully understand it's secret. I will read the reference you quoted.

    – jarod.tian
    Dec 27 '15 at 2:28
















8














You can’t do that in either Scheme or Common Lisp without macros. Of course, it’s also pretty trivial with macros, so feel free to use them if they fit your use case.



That said, there’s a bit more to this question than you may have anticipated. You’re effectively asking for a feature that was present in older Lisps that has fallen out of fashion, known as fexprs. A fexpr is exactly what you describe: a function whose operands are passed to it without being evaluated.



Most modern dialects have done away with fexprs in favor of only using macros, and you can see this Stack Overflow question for more information on why. The gist is that fexprs are hard to optimize, difficult to reason about, and generally less powerful than macros, so they were deemed both redundant and actively harmful and were summarily removed.



Some modern Lisps still support fexprs or something like them, but those dialects are rare and uncommon in comparison to the relative giants that are Scheme and CL, which dominate the modern Lisp world. If you need this sort of thing, just use macros. Better yet, just quote the arguments so you don’t need any macros at all. You’ll be more explicit (and therefore much clearer), and you’ll get the same behavior.






share|improve this answer


























  • As far as I remember, fexprs where an experimental side track in a few dialects, but never something you'd generally expect from a Lisp.

    – Svante
    Dec 25 '15 at 0:40











  • Thanks Alexis! Your answer opened my eye a lot. Actually I had this question when I was reading the book <practical common lisp>. I was thinking why I cannot use plain function rather than macro. That means why macro is necessary. So I tried to simulate macro's behaviour by writing the function "foo" in this question. Maybe I need more thinking about "macro" to fully understand it's secret. I will read the reference you quoted.

    – jarod.tian
    Dec 27 '15 at 2:28














8












8








8







You can’t do that in either Scheme or Common Lisp without macros. Of course, it’s also pretty trivial with macros, so feel free to use them if they fit your use case.



That said, there’s a bit more to this question than you may have anticipated. You’re effectively asking for a feature that was present in older Lisps that has fallen out of fashion, known as fexprs. A fexpr is exactly what you describe: a function whose operands are passed to it without being evaluated.



Most modern dialects have done away with fexprs in favor of only using macros, and you can see this Stack Overflow question for more information on why. The gist is that fexprs are hard to optimize, difficult to reason about, and generally less powerful than macros, so they were deemed both redundant and actively harmful and were summarily removed.



Some modern Lisps still support fexprs or something like them, but those dialects are rare and uncommon in comparison to the relative giants that are Scheme and CL, which dominate the modern Lisp world. If you need this sort of thing, just use macros. Better yet, just quote the arguments so you don’t need any macros at all. You’ll be more explicit (and therefore much clearer), and you’ll get the same behavior.






share|improve this answer















You can’t do that in either Scheme or Common Lisp without macros. Of course, it’s also pretty trivial with macros, so feel free to use them if they fit your use case.



That said, there’s a bit more to this question than you may have anticipated. You’re effectively asking for a feature that was present in older Lisps that has fallen out of fashion, known as fexprs. A fexpr is exactly what you describe: a function whose operands are passed to it without being evaluated.



Most modern dialects have done away with fexprs in favor of only using macros, and you can see this Stack Overflow question for more information on why. The gist is that fexprs are hard to optimize, difficult to reason about, and generally less powerful than macros, so they were deemed both redundant and actively harmful and were summarily removed.



Some modern Lisps still support fexprs or something like them, but those dialects are rare and uncommon in comparison to the relative giants that are Scheme and CL, which dominate the modern Lisp world. If you need this sort of thing, just use macros. Better yet, just quote the arguments so you don’t need any macros at all. You’ll be more explicit (and therefore much clearer), and you’ll get the same behavior.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 23:29

























answered Dec 24 '15 at 9:01









Alexis KingAlexis King

32.8k1199171




32.8k1199171













  • As far as I remember, fexprs where an experimental side track in a few dialects, but never something you'd generally expect from a Lisp.

    – Svante
    Dec 25 '15 at 0:40











  • Thanks Alexis! Your answer opened my eye a lot. Actually I had this question when I was reading the book <practical common lisp>. I was thinking why I cannot use plain function rather than macro. That means why macro is necessary. So I tried to simulate macro's behaviour by writing the function "foo" in this question. Maybe I need more thinking about "macro" to fully understand it's secret. I will read the reference you quoted.

    – jarod.tian
    Dec 27 '15 at 2:28



















  • As far as I remember, fexprs where an experimental side track in a few dialects, but never something you'd generally expect from a Lisp.

    – Svante
    Dec 25 '15 at 0:40











  • Thanks Alexis! Your answer opened my eye a lot. Actually I had this question when I was reading the book <practical common lisp>. I was thinking why I cannot use plain function rather than macro. That means why macro is necessary. So I tried to simulate macro's behaviour by writing the function "foo" in this question. Maybe I need more thinking about "macro" to fully understand it's secret. I will read the reference you quoted.

    – jarod.tian
    Dec 27 '15 at 2:28

















As far as I remember, fexprs where an experimental side track in a few dialects, but never something you'd generally expect from a Lisp.

– Svante
Dec 25 '15 at 0:40





As far as I remember, fexprs where an experimental side track in a few dialects, but never something you'd generally expect from a Lisp.

– Svante
Dec 25 '15 at 0:40













Thanks Alexis! Your answer opened my eye a lot. Actually I had this question when I was reading the book <practical common lisp>. I was thinking why I cannot use plain function rather than macro. That means why macro is necessary. So I tried to simulate macro's behaviour by writing the function "foo" in this question. Maybe I need more thinking about "macro" to fully understand it's secret. I will read the reference you quoted.

– jarod.tian
Dec 27 '15 at 2:28





Thanks Alexis! Your answer opened my eye a lot. Actually I had this question when I was reading the book <practical common lisp>. I was thinking why I cannot use plain function rather than macro. That means why macro is necessary. So I tried to simulate macro's behaviour by writing the function "foo" in this question. Maybe I need more thinking about "macro" to fully understand it's secret. I will read the reference you quoted.

– jarod.tian
Dec 27 '15 at 2:28













2














Yes; you can get the result with an operator called quote, if you don't mind one more level of nesting:



(quote ((= 1 2) (< 2 3)))
-> ((1 2) (2 3))


quote isn't a macro; it is a special operator.






share|improve this answer
























  • Thanks Kaz! It works without "macro".

    – jarod.tian
    Dec 27 '15 at 2:21
















2














Yes; you can get the result with an operator called quote, if you don't mind one more level of nesting:



(quote ((= 1 2) (< 2 3)))
-> ((1 2) (2 3))


quote isn't a macro; it is a special operator.






share|improve this answer
























  • Thanks Kaz! It works without "macro".

    – jarod.tian
    Dec 27 '15 at 2:21














2












2








2







Yes; you can get the result with an operator called quote, if you don't mind one more level of nesting:



(quote ((= 1 2) (< 2 3)))
-> ((1 2) (2 3))


quote isn't a macro; it is a special operator.






share|improve this answer













Yes; you can get the result with an operator called quote, if you don't mind one more level of nesting:



(quote ((= 1 2) (< 2 3)))
-> ((1 2) (2 3))


quote isn't a macro; it is a special operator.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 25 '15 at 0:37









KazKaz

38.8k768108




38.8k768108













  • Thanks Kaz! It works without "macro".

    – jarod.tian
    Dec 27 '15 at 2:21



















  • Thanks Kaz! It works without "macro".

    – jarod.tian
    Dec 27 '15 at 2:21

















Thanks Kaz! It works without "macro".

– jarod.tian
Dec 27 '15 at 2:21





Thanks Kaz! It works without "macro".

– jarod.tian
Dec 27 '15 at 2:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34446324%2fprint-arguments-of-function-call-without-evaluation-not-using-macro%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python