Understanding the symbols in scheme









up vote
-1
down vote

favorite












Can you help me understand why there are 7 symbols (including duplicates) in the value of the following expression ?



​'('a ',(string->symbol "b") 'c))









share|improve this question



























    up vote
    -1
    down vote

    favorite












    Can you help me understand why there are 7 symbols (including duplicates) in the value of the following expression ?



    ​'('a ',(string->symbol "b") 'c))









    share|improve this question

























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      Can you help me understand why there are 7 symbols (including duplicates) in the value of the following expression ?



      ​'('a ',(string->symbol "b") 'c))









      share|improve this question















      Can you help me understand why there are 7 symbols (including duplicates) in the value of the following expression ?



      ​'('a ',(string->symbol "b") 'c))






      scheme






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 20:36









      Graham

      3,316123558




      3,316123558










      asked Nov 9 at 19:42









      Shir Cohen

      6




      6






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          You can write a function that checks whether elements are symbols.

          Pair the element with its "symbolness" for clarity:



          (define (sym-check ls)
          (cond ((null? ls) '())
          ((not (pair? ls)) (cons ls (symbol? ls)))
          ((pair? (car ls)) (cons (map sym-check (car ls)) (sym-check (cdr ls))))
          (else (cons (sym-check (car ls)) (sym-check (cdr ls))))))

          > (sym-check '('a ',(string->symbol "b") 'c))
          '(((quote . #t) (a . #t)) ((quote . #t)
          ((unquote . #t)
          ((string->symbol . #t) ("b" . #f))))
          ((quote . #t) (c . #t)))


          and you get seven #ts.

          Note that' and , are "shorthand" for the symbols quote and unquote,



          > (quote (unquote (string->symbol "b")))
          ',(string->symbol "b")


          and that using list instead of quoting gives a very different result:



          > (sym-check (list 'a ',(string->symbol "b") 'c))
          '((a . #t) ((unquote . #t) ((string->symbol . #t) ("b" . #f))) (c . #t))


          which is the same as leaving quoting out of the quoted list:



          > (sym-check '(a ,(string->symbol "b") c))
          '((a . #t) ((unquote . #t) ((string->symbol . #t) ("b" . #f))) (c . #t))





          share|improve this answer



























            up vote
            1
            down vote













            '('a ',(string->symbol "b") 'c)) evaluates to the following structure:



            ((quote a) 
            (quote (unquote (string->symbol "b")))
            (quote c))


            I can count 7 so yes. It is 7 symbols in the result of evaluating the quoted expression.



            Scheme system has a reader that translates 'x to (quote x) and ,, `, and ,@ corresponds to forms with quasiquote, unquote, and unquote-splicing. That means that the code `(a b c ,d e f) becomes (quasiquote (a b c (unquote d) e f)). Then the macos in the implementation translates it into (list* 'a 'b 'c d '(e f)) or a similar expression that does the same. However with '`(a b c ,d e f) just becomes the value (quasiquote (a b c (unquote d) e f)) since that is the expression that was quoted. Scheme doesn't expand into normal quote expression.



            Usually quote characters inside quoted datum is a bug. Beginners doesn't understand the purpose and thin it needs to be everywhere. But really you only need the outer quote. (+ 4 5) is 9 and '(+ 4 5) is (+ 4 5). See the difference?






            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',
              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%2f53232308%2funderstanding-the-symbols-in-scheme%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








              up vote
              1
              down vote













              You can write a function that checks whether elements are symbols.

              Pair the element with its "symbolness" for clarity:



              (define (sym-check ls)
              (cond ((null? ls) '())
              ((not (pair? ls)) (cons ls (symbol? ls)))
              ((pair? (car ls)) (cons (map sym-check (car ls)) (sym-check (cdr ls))))
              (else (cons (sym-check (car ls)) (sym-check (cdr ls))))))

              > (sym-check '('a ',(string->symbol "b") 'c))
              '(((quote . #t) (a . #t)) ((quote . #t)
              ((unquote . #t)
              ((string->symbol . #t) ("b" . #f))))
              ((quote . #t) (c . #t)))


              and you get seven #ts.

              Note that' and , are "shorthand" for the symbols quote and unquote,



              > (quote (unquote (string->symbol "b")))
              ',(string->symbol "b")


              and that using list instead of quoting gives a very different result:



              > (sym-check (list 'a ',(string->symbol "b") 'c))
              '((a . #t) ((unquote . #t) ((string->symbol . #t) ("b" . #f))) (c . #t))


              which is the same as leaving quoting out of the quoted list:



              > (sym-check '(a ,(string->symbol "b") c))
              '((a . #t) ((unquote . #t) ((string->symbol . #t) ("b" . #f))) (c . #t))





              share|improve this answer
























                up vote
                1
                down vote













                You can write a function that checks whether elements are symbols.

                Pair the element with its "symbolness" for clarity:



                (define (sym-check ls)
                (cond ((null? ls) '())
                ((not (pair? ls)) (cons ls (symbol? ls)))
                ((pair? (car ls)) (cons (map sym-check (car ls)) (sym-check (cdr ls))))
                (else (cons (sym-check (car ls)) (sym-check (cdr ls))))))

                > (sym-check '('a ',(string->symbol "b") 'c))
                '(((quote . #t) (a . #t)) ((quote . #t)
                ((unquote . #t)
                ((string->symbol . #t) ("b" . #f))))
                ((quote . #t) (c . #t)))


                and you get seven #ts.

                Note that' and , are "shorthand" for the symbols quote and unquote,



                > (quote (unquote (string->symbol "b")))
                ',(string->symbol "b")


                and that using list instead of quoting gives a very different result:



                > (sym-check (list 'a ',(string->symbol "b") 'c))
                '((a . #t) ((unquote . #t) ((string->symbol . #t) ("b" . #f))) (c . #t))


                which is the same as leaving quoting out of the quoted list:



                > (sym-check '(a ,(string->symbol "b") c))
                '((a . #t) ((unquote . #t) ((string->symbol . #t) ("b" . #f))) (c . #t))





                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  You can write a function that checks whether elements are symbols.

                  Pair the element with its "symbolness" for clarity:



                  (define (sym-check ls)
                  (cond ((null? ls) '())
                  ((not (pair? ls)) (cons ls (symbol? ls)))
                  ((pair? (car ls)) (cons (map sym-check (car ls)) (sym-check (cdr ls))))
                  (else (cons (sym-check (car ls)) (sym-check (cdr ls))))))

                  > (sym-check '('a ',(string->symbol "b") 'c))
                  '(((quote . #t) (a . #t)) ((quote . #t)
                  ((unquote . #t)
                  ((string->symbol . #t) ("b" . #f))))
                  ((quote . #t) (c . #t)))


                  and you get seven #ts.

                  Note that' and , are "shorthand" for the symbols quote and unquote,



                  > (quote (unquote (string->symbol "b")))
                  ',(string->symbol "b")


                  and that using list instead of quoting gives a very different result:



                  > (sym-check (list 'a ',(string->symbol "b") 'c))
                  '((a . #t) ((unquote . #t) ((string->symbol . #t) ("b" . #f))) (c . #t))


                  which is the same as leaving quoting out of the quoted list:



                  > (sym-check '(a ,(string->symbol "b") c))
                  '((a . #t) ((unquote . #t) ((string->symbol . #t) ("b" . #f))) (c . #t))





                  share|improve this answer












                  You can write a function that checks whether elements are symbols.

                  Pair the element with its "symbolness" for clarity:



                  (define (sym-check ls)
                  (cond ((null? ls) '())
                  ((not (pair? ls)) (cons ls (symbol? ls)))
                  ((pair? (car ls)) (cons (map sym-check (car ls)) (sym-check (cdr ls))))
                  (else (cons (sym-check (car ls)) (sym-check (cdr ls))))))

                  > (sym-check '('a ',(string->symbol "b") 'c))
                  '(((quote . #t) (a . #t)) ((quote . #t)
                  ((unquote . #t)
                  ((string->symbol . #t) ("b" . #f))))
                  ((quote . #t) (c . #t)))


                  and you get seven #ts.

                  Note that' and , are "shorthand" for the symbols quote and unquote,



                  > (quote (unquote (string->symbol "b")))
                  ',(string->symbol "b")


                  and that using list instead of quoting gives a very different result:



                  > (sym-check (list 'a ',(string->symbol "b") 'c))
                  '((a . #t) ((unquote . #t) ((string->symbol . #t) ("b" . #f))) (c . #t))


                  which is the same as leaving quoting out of the quoted list:



                  > (sym-check '(a ,(string->symbol "b") c))
                  '((a . #t) ((unquote . #t) ((string->symbol . #t) ("b" . #f))) (c . #t))






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 9 at 21:55









                  molbdnilo

                  39.8k32152




                  39.8k32152






















                      up vote
                      1
                      down vote













                      '('a ',(string->symbol "b") 'c)) evaluates to the following structure:



                      ((quote a) 
                      (quote (unquote (string->symbol "b")))
                      (quote c))


                      I can count 7 so yes. It is 7 symbols in the result of evaluating the quoted expression.



                      Scheme system has a reader that translates 'x to (quote x) and ,, `, and ,@ corresponds to forms with quasiquote, unquote, and unquote-splicing. That means that the code `(a b c ,d e f) becomes (quasiquote (a b c (unquote d) e f)). Then the macos in the implementation translates it into (list* 'a 'b 'c d '(e f)) or a similar expression that does the same. However with '`(a b c ,d e f) just becomes the value (quasiquote (a b c (unquote d) e f)) since that is the expression that was quoted. Scheme doesn't expand into normal quote expression.



                      Usually quote characters inside quoted datum is a bug. Beginners doesn't understand the purpose and thin it needs to be everywhere. But really you only need the outer quote. (+ 4 5) is 9 and '(+ 4 5) is (+ 4 5). See the difference?






                      share|improve this answer
























                        up vote
                        1
                        down vote













                        '('a ',(string->symbol "b") 'c)) evaluates to the following structure:



                        ((quote a) 
                        (quote (unquote (string->symbol "b")))
                        (quote c))


                        I can count 7 so yes. It is 7 symbols in the result of evaluating the quoted expression.



                        Scheme system has a reader that translates 'x to (quote x) and ,, `, and ,@ corresponds to forms with quasiquote, unquote, and unquote-splicing. That means that the code `(a b c ,d e f) becomes (quasiquote (a b c (unquote d) e f)). Then the macos in the implementation translates it into (list* 'a 'b 'c d '(e f)) or a similar expression that does the same. However with '`(a b c ,d e f) just becomes the value (quasiquote (a b c (unquote d) e f)) since that is the expression that was quoted. Scheme doesn't expand into normal quote expression.



                        Usually quote characters inside quoted datum is a bug. Beginners doesn't understand the purpose and thin it needs to be everywhere. But really you only need the outer quote. (+ 4 5) is 9 and '(+ 4 5) is (+ 4 5). See the difference?






                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          '('a ',(string->symbol "b") 'c)) evaluates to the following structure:



                          ((quote a) 
                          (quote (unquote (string->symbol "b")))
                          (quote c))


                          I can count 7 so yes. It is 7 symbols in the result of evaluating the quoted expression.



                          Scheme system has a reader that translates 'x to (quote x) and ,, `, and ,@ corresponds to forms with quasiquote, unquote, and unquote-splicing. That means that the code `(a b c ,d e f) becomes (quasiquote (a b c (unquote d) e f)). Then the macos in the implementation translates it into (list* 'a 'b 'c d '(e f)) or a similar expression that does the same. However with '`(a b c ,d e f) just becomes the value (quasiquote (a b c (unquote d) e f)) since that is the expression that was quoted. Scheme doesn't expand into normal quote expression.



                          Usually quote characters inside quoted datum is a bug. Beginners doesn't understand the purpose and thin it needs to be everywhere. But really you only need the outer quote. (+ 4 5) is 9 and '(+ 4 5) is (+ 4 5). See the difference?






                          share|improve this answer












                          '('a ',(string->symbol "b") 'c)) evaluates to the following structure:



                          ((quote a) 
                          (quote (unquote (string->symbol "b")))
                          (quote c))


                          I can count 7 so yes. It is 7 symbols in the result of evaluating the quoted expression.



                          Scheme system has a reader that translates 'x to (quote x) and ,, `, and ,@ corresponds to forms with quasiquote, unquote, and unquote-splicing. That means that the code `(a b c ,d e f) becomes (quasiquote (a b c (unquote d) e f)). Then the macos in the implementation translates it into (list* 'a 'b 'c d '(e f)) or a similar expression that does the same. However with '`(a b c ,d e f) just becomes the value (quasiquote (a b c (unquote d) e f)) since that is the expression that was quoted. Scheme doesn't expand into normal quote expression.



                          Usually quote characters inside quoted datum is a bug. Beginners doesn't understand the purpose and thin it needs to be everywhere. But really you only need the outer quote. (+ 4 5) is 9 and '(+ 4 5) is (+ 4 5). See the difference?







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 10 at 0:52









                          Sylwester

                          33.5k22854




                          33.5k22854



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232308%2funderstanding-the-symbols-in-scheme%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

                              Use pre created SQLite database for Android project in kotlin

                              Darth Vader #20

                              Ondo