How to use quote and unquote to more faithfully translate The Reasoned Schemer into Racket?












1















(Details of my miniKanren in Racket setup appear at the bottom[1].)



The way quotes and unquotes work in The Reasoned Schemer appears not to match the way they work in Racket. For instance, verse 2 of chapter 2 suggests[2] the following function definition:



(run #f
(r )
(fresh (y x )
(== '(,x ,y) r )))


If I evaluate that, I get '((,x ,y)). If instead I rewrite it as this:



(run #f
(r )
(fresh (y x )
(== (list x y) r)))


I get the expected result, '((_.0 _.1)).



This might seem like a minor problem, but in many cases the required translation is extremely verbose. For instance, in exercise 45 of chapter 3 (page 34), the book provides, roughly[3] the following definition:



(run 5 (r)
(fresh (w x y z)
(loto (('g 'g) ('e w) (x y) . z))
(== (w (x y) z) r)))


In order to get the results they get, I had to rewrite it like this:



(run 5 (r)
(fresh (w x y z)
(loto (cons '(g g)
(cons (list 'e w)
(cons (list x y)
z))))
(== (list w (list x y) z)
r)))


[1] As described here, I ran raco pkg install minikanren and then defined a few missing pieces.



[2] Actually, they don't write precisely that, but if you heed the advice in the footnotes to that verse and an earlier verse, it's what you get.



[3] Modulo some implicit quoting and unquoting that I cannot deduce.










share|improve this question




















  • 4





    Looks like you should use quasiquote instead of quote.

    – PetSerAl
    Nov 16 '18 at 5:31






  • 1





    quasiquote is the one written with a backtick ( `` ` `` ) which is on the same key as tilde (~), not the normal tick (')

    – Alex Knauth
    Nov 16 '18 at 6:12








  • 1





    Also note that (cons '(g g) (cons (list 'e w) (cons (list x y) z))) can be written as (list* '(g g) (list 'e w) (list x y) z).

    – PetSerAl
    Nov 17 '18 at 18:32






  • 1





    @JeffreyBenjaminBrown Can you show example when this is not true? Assuming cons and list* have their normal definitions, AFAIK, (list* a b c d e) should be the same as (cons a (cons b (cons c (cons d e)))). ideone.com/rxqmB5

    – PetSerAl
    Nov 17 '18 at 19:52






  • 1





    @JeffreyBenjaminBrown (list 1 3) is (1 3), but (list* 1 3) is (1 . 3).

    – PetSerAl
    Nov 17 '18 at 20:02
















1















(Details of my miniKanren in Racket setup appear at the bottom[1].)



The way quotes and unquotes work in The Reasoned Schemer appears not to match the way they work in Racket. For instance, verse 2 of chapter 2 suggests[2] the following function definition:



(run #f
(r )
(fresh (y x )
(== '(,x ,y) r )))


If I evaluate that, I get '((,x ,y)). If instead I rewrite it as this:



(run #f
(r )
(fresh (y x )
(== (list x y) r)))


I get the expected result, '((_.0 _.1)).



This might seem like a minor problem, but in many cases the required translation is extremely verbose. For instance, in exercise 45 of chapter 3 (page 34), the book provides, roughly[3] the following definition:



(run 5 (r)
(fresh (w x y z)
(loto (('g 'g) ('e w) (x y) . z))
(== (w (x y) z) r)))


In order to get the results they get, I had to rewrite it like this:



(run 5 (r)
(fresh (w x y z)
(loto (cons '(g g)
(cons (list 'e w)
(cons (list x y)
z))))
(== (list w (list x y) z)
r)))


[1] As described here, I ran raco pkg install minikanren and then defined a few missing pieces.



[2] Actually, they don't write precisely that, but if you heed the advice in the footnotes to that verse and an earlier verse, it's what you get.



[3] Modulo some implicit quoting and unquoting that I cannot deduce.










share|improve this question




















  • 4





    Looks like you should use quasiquote instead of quote.

    – PetSerAl
    Nov 16 '18 at 5:31






  • 1





    quasiquote is the one written with a backtick ( `` ` `` ) which is on the same key as tilde (~), not the normal tick (')

    – Alex Knauth
    Nov 16 '18 at 6:12








  • 1





    Also note that (cons '(g g) (cons (list 'e w) (cons (list x y) z))) can be written as (list* '(g g) (list 'e w) (list x y) z).

    – PetSerAl
    Nov 17 '18 at 18:32






  • 1





    @JeffreyBenjaminBrown Can you show example when this is not true? Assuming cons and list* have their normal definitions, AFAIK, (list* a b c d e) should be the same as (cons a (cons b (cons c (cons d e)))). ideone.com/rxqmB5

    – PetSerAl
    Nov 17 '18 at 19:52






  • 1





    @JeffreyBenjaminBrown (list 1 3) is (1 3), but (list* 1 3) is (1 . 3).

    – PetSerAl
    Nov 17 '18 at 20:02














1












1








1


0






(Details of my miniKanren in Racket setup appear at the bottom[1].)



The way quotes and unquotes work in The Reasoned Schemer appears not to match the way they work in Racket. For instance, verse 2 of chapter 2 suggests[2] the following function definition:



(run #f
(r )
(fresh (y x )
(== '(,x ,y) r )))


If I evaluate that, I get '((,x ,y)). If instead I rewrite it as this:



(run #f
(r )
(fresh (y x )
(== (list x y) r)))


I get the expected result, '((_.0 _.1)).



This might seem like a minor problem, but in many cases the required translation is extremely verbose. For instance, in exercise 45 of chapter 3 (page 34), the book provides, roughly[3] the following definition:



(run 5 (r)
(fresh (w x y z)
(loto (('g 'g) ('e w) (x y) . z))
(== (w (x y) z) r)))


In order to get the results they get, I had to rewrite it like this:



(run 5 (r)
(fresh (w x y z)
(loto (cons '(g g)
(cons (list 'e w)
(cons (list x y)
z))))
(== (list w (list x y) z)
r)))


[1] As described here, I ran raco pkg install minikanren and then defined a few missing pieces.



[2] Actually, they don't write precisely that, but if you heed the advice in the footnotes to that verse and an earlier verse, it's what you get.



[3] Modulo some implicit quoting and unquoting that I cannot deduce.










share|improve this question
















(Details of my miniKanren in Racket setup appear at the bottom[1].)



The way quotes and unquotes work in The Reasoned Schemer appears not to match the way they work in Racket. For instance, verse 2 of chapter 2 suggests[2] the following function definition:



(run #f
(r )
(fresh (y x )
(== '(,x ,y) r )))


If I evaluate that, I get '((,x ,y)). If instead I rewrite it as this:



(run #f
(r )
(fresh (y x )
(== (list x y) r)))


I get the expected result, '((_.0 _.1)).



This might seem like a minor problem, but in many cases the required translation is extremely verbose. For instance, in exercise 45 of chapter 3 (page 34), the book provides, roughly[3] the following definition:



(run 5 (r)
(fresh (w x y z)
(loto (('g 'g) ('e w) (x y) . z))
(== (w (x y) z) r)))


In order to get the results they get, I had to rewrite it like this:



(run 5 (r)
(fresh (w x y z)
(loto (cons '(g g)
(cons (list 'e w)
(cons (list x y)
z))))
(== (list w (list x y) z)
r)))


[1] As described here, I ran raco pkg install minikanren and then defined a few missing pieces.



[2] Actually, they don't write precisely that, but if you heed the advice in the footnotes to that verse and an earlier verse, it's what you get.



[3] Modulo some implicit quoting and unquoting that I cannot deduce.







scheme racket quote minikanren






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 3:42







Jeffrey Benjamin Brown

















asked Nov 16 '18 at 3:35









Jeffrey Benjamin BrownJeffrey Benjamin Brown

9862923




9862923








  • 4





    Looks like you should use quasiquote instead of quote.

    – PetSerAl
    Nov 16 '18 at 5:31






  • 1





    quasiquote is the one written with a backtick ( `` ` `` ) which is on the same key as tilde (~), not the normal tick (')

    – Alex Knauth
    Nov 16 '18 at 6:12








  • 1





    Also note that (cons '(g g) (cons (list 'e w) (cons (list x y) z))) can be written as (list* '(g g) (list 'e w) (list x y) z).

    – PetSerAl
    Nov 17 '18 at 18:32






  • 1





    @JeffreyBenjaminBrown Can you show example when this is not true? Assuming cons and list* have their normal definitions, AFAIK, (list* a b c d e) should be the same as (cons a (cons b (cons c (cons d e)))). ideone.com/rxqmB5

    – PetSerAl
    Nov 17 '18 at 19:52






  • 1





    @JeffreyBenjaminBrown (list 1 3) is (1 3), but (list* 1 3) is (1 . 3).

    – PetSerAl
    Nov 17 '18 at 20:02














  • 4





    Looks like you should use quasiquote instead of quote.

    – PetSerAl
    Nov 16 '18 at 5:31






  • 1





    quasiquote is the one written with a backtick ( `` ` `` ) which is on the same key as tilde (~), not the normal tick (')

    – Alex Knauth
    Nov 16 '18 at 6:12








  • 1





    Also note that (cons '(g g) (cons (list 'e w) (cons (list x y) z))) can be written as (list* '(g g) (list 'e w) (list x y) z).

    – PetSerAl
    Nov 17 '18 at 18:32






  • 1





    @JeffreyBenjaminBrown Can you show example when this is not true? Assuming cons and list* have their normal definitions, AFAIK, (list* a b c d e) should be the same as (cons a (cons b (cons c (cons d e)))). ideone.com/rxqmB5

    – PetSerAl
    Nov 17 '18 at 19:52






  • 1





    @JeffreyBenjaminBrown (list 1 3) is (1 3), but (list* 1 3) is (1 . 3).

    – PetSerAl
    Nov 17 '18 at 20:02








4




4





Looks like you should use quasiquote instead of quote.

– PetSerAl
Nov 16 '18 at 5:31





Looks like you should use quasiquote instead of quote.

– PetSerAl
Nov 16 '18 at 5:31




1




1





quasiquote is the one written with a backtick ( `` ` `` ) which is on the same key as tilde (~), not the normal tick (')

– Alex Knauth
Nov 16 '18 at 6:12







quasiquote is the one written with a backtick ( `` ` `` ) which is on the same key as tilde (~), not the normal tick (')

– Alex Knauth
Nov 16 '18 at 6:12






1




1





Also note that (cons '(g g) (cons (list 'e w) (cons (list x y) z))) can be written as (list* '(g g) (list 'e w) (list x y) z).

– PetSerAl
Nov 17 '18 at 18:32





Also note that (cons '(g g) (cons (list 'e w) (cons (list x y) z))) can be written as (list* '(g g) (list 'e w) (list x y) z).

– PetSerAl
Nov 17 '18 at 18:32




1




1





@JeffreyBenjaminBrown Can you show example when this is not true? Assuming cons and list* have their normal definitions, AFAIK, (list* a b c d e) should be the same as (cons a (cons b (cons c (cons d e)))). ideone.com/rxqmB5

– PetSerAl
Nov 17 '18 at 19:52





@JeffreyBenjaminBrown Can you show example when this is not true? Assuming cons and list* have their normal definitions, AFAIK, (list* a b c d e) should be the same as (cons a (cons b (cons c (cons d e)))). ideone.com/rxqmB5

– PetSerAl
Nov 17 '18 at 19:52




1




1





@JeffreyBenjaminBrown (list 1 3) is (1 3), but (list* 1 3) is (1 . 3).

– PetSerAl
Nov 17 '18 at 20:02





@JeffreyBenjaminBrown (list 1 3) is (1 3), but (list* 1 3) is (1 . 3).

– PetSerAl
Nov 17 '18 at 20:02












1 Answer
1






active

oldest

votes


















2














Use the backquote ` instead of the simple quote ' you have been using.






share|improve this answer























    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%2f53331052%2fhow-to-use-quote-and-unquote-to-more-faithfully-translate-the-reasoned-schemer-i%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Use the backquote ` instead of the simple quote ' you have been using.






    share|improve this answer




























      2














      Use the backquote ` instead of the simple quote ' you have been using.






      share|improve this answer


























        2












        2








        2







        Use the backquote ` instead of the simple quote ' you have been using.






        share|improve this answer













        Use the backquote ` instead of the simple quote ' you have been using.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 3 '18 at 8:03









        Will NessWill Ness

        46.4k468126




        46.4k468126
































            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%2f53331052%2fhow-to-use-quote-and-unquote-to-more-faithfully-translate-the-reasoned-schemer-i%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

            Bressuire

            Vorschmack

            Quarantine