Multiple return values of floor in dotimes












2















The floor Hyperspec article on dotimes has this example:



(defun palindromep (string &optional
(start 0)
(end (length string)))
(dotimes (k (floor (- end start) 2) t)
(unless (char-equal (char string (+ start k))
(char string (- end k 1)))
(return nil))))


If floor returns two values, e.g. (floor 5 2) -> 2 and 1, how does dotimes know to just use the first value and disregard the second for its count-form?










share|improve this question





























    2















    The floor Hyperspec article on dotimes has this example:



    (defun palindromep (string &optional
    (start 0)
    (end (length string)))
    (dotimes (k (floor (- end start) 2) t)
    (unless (char-equal (char string (+ start k))
    (char string (- end k 1)))
    (return nil))))


    If floor returns two values, e.g. (floor 5 2) -> 2 and 1, how does dotimes know to just use the first value and disregard the second for its count-form?










    share|improve this question



























      2












      2








      2








      The floor Hyperspec article on dotimes has this example:



      (defun palindromep (string &optional
      (start 0)
      (end (length string)))
      (dotimes (k (floor (- end start) 2) t)
      (unless (char-equal (char string (+ start k))
      (char string (- end k 1)))
      (return nil))))


      If floor returns two values, e.g. (floor 5 2) -> 2 and 1, how does dotimes know to just use the first value and disregard the second for its count-form?










      share|improve this question
















      The floor Hyperspec article on dotimes has this example:



      (defun palindromep (string &optional
      (start 0)
      (end (length string)))
      (dotimes (k (floor (- end start) 2) t)
      (unless (char-equal (char string (+ start k))
      (char string (- end k 1)))
      (return nil))))


      If floor returns two values, e.g. (floor 5 2) -> 2 and 1, how does dotimes know to just use the first value and disregard the second for its count-form?







      common-lisp floor multiple-value






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 9:34









      coredump

      21.3k33046




      21.3k33046










      asked Nov 22 '18 at 18:41









      147pm147pm

      582416




      582416
























          2 Answers
          2






          active

          oldest

          votes


















          6














          From 7.10.1,




          Normally multiple values are not used. Special forms are required both to produce multiple values and to receive them. If the caller of a function does not request multiple values, but the called function produces multiple values, then the first value is given to the caller and all others are discarded; if the called function produces zero values, then the caller gets nil as a value.




          Unless you specifically do something to deal with the multiple values (such as by multiple-value-call or one of the various macros equipped to handle them), all except the first value will be ignored.






          share|improve this answer































            7














            It's a general mechanism and not specific to dotimes.



            If one calls a function or sets a variable, then only the first value will be passed:



            CL-USER 52 > (defun foo (x) x)
            FOO

            CL-USER 53 > (foo (floor 5 2))
            2

            CL-USER 54 > (let ((foo (floor 5 2)))
            foo)
            2


            To do the equivalent (calling functions, binding variables) with multiple values, one needs to use special constructs:



            CL-USER 55 > (multiple-value-call #'list
            (floor 5 2) (floor 7 3))
            (2 1 2 1)

            CL-USER 56 > (multiple-value-bind (foo0 foo1)
            (floor 5 2)
            (list foo0 foo1))
            (2 1)





            share|improve this answer


























            • Is this an example of functional's basic lambda calculus need/tendency to curry?

              – 147pm
              Nov 22 '18 at 21:11











            • @147pm: no, that's unrelated

              – Rainer Joswig
              Nov 22 '18 at 21:16











            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%2f53436620%2fmultiple-return-values-of-floor-in-dotimes%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









            6














            From 7.10.1,




            Normally multiple values are not used. Special forms are required both to produce multiple values and to receive them. If the caller of a function does not request multiple values, but the called function produces multiple values, then the first value is given to the caller and all others are discarded; if the called function produces zero values, then the caller gets nil as a value.




            Unless you specifically do something to deal with the multiple values (such as by multiple-value-call or one of the various macros equipped to handle them), all except the first value will be ignored.






            share|improve this answer




























              6














              From 7.10.1,




              Normally multiple values are not used. Special forms are required both to produce multiple values and to receive them. If the caller of a function does not request multiple values, but the called function produces multiple values, then the first value is given to the caller and all others are discarded; if the called function produces zero values, then the caller gets nil as a value.




              Unless you specifically do something to deal with the multiple values (such as by multiple-value-call or one of the various macros equipped to handle them), all except the first value will be ignored.






              share|improve this answer


























                6












                6








                6







                From 7.10.1,




                Normally multiple values are not used. Special forms are required both to produce multiple values and to receive them. If the caller of a function does not request multiple values, but the called function produces multiple values, then the first value is given to the caller and all others are discarded; if the called function produces zero values, then the caller gets nil as a value.




                Unless you specifically do something to deal with the multiple values (such as by multiple-value-call or one of the various macros equipped to handle them), all except the first value will be ignored.






                share|improve this answer













                From 7.10.1,




                Normally multiple values are not used. Special forms are required both to produce multiple values and to receive them. If the caller of a function does not request multiple values, but the called function produces multiple values, then the first value is given to the caller and all others are discarded; if the called function produces zero values, then the caller gets nil as a value.




                Unless you specifically do something to deal with the multiple values (such as by multiple-value-call or one of the various macros equipped to handle them), all except the first value will be ignored.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 '18 at 18:48









                Silvio MayoloSilvio Mayolo

                14.1k22453




                14.1k22453

























                    7














                    It's a general mechanism and not specific to dotimes.



                    If one calls a function or sets a variable, then only the first value will be passed:



                    CL-USER 52 > (defun foo (x) x)
                    FOO

                    CL-USER 53 > (foo (floor 5 2))
                    2

                    CL-USER 54 > (let ((foo (floor 5 2)))
                    foo)
                    2


                    To do the equivalent (calling functions, binding variables) with multiple values, one needs to use special constructs:



                    CL-USER 55 > (multiple-value-call #'list
                    (floor 5 2) (floor 7 3))
                    (2 1 2 1)

                    CL-USER 56 > (multiple-value-bind (foo0 foo1)
                    (floor 5 2)
                    (list foo0 foo1))
                    (2 1)





                    share|improve this answer


























                    • Is this an example of functional's basic lambda calculus need/tendency to curry?

                      – 147pm
                      Nov 22 '18 at 21:11











                    • @147pm: no, that's unrelated

                      – Rainer Joswig
                      Nov 22 '18 at 21:16
















                    7














                    It's a general mechanism and not specific to dotimes.



                    If one calls a function or sets a variable, then only the first value will be passed:



                    CL-USER 52 > (defun foo (x) x)
                    FOO

                    CL-USER 53 > (foo (floor 5 2))
                    2

                    CL-USER 54 > (let ((foo (floor 5 2)))
                    foo)
                    2


                    To do the equivalent (calling functions, binding variables) with multiple values, one needs to use special constructs:



                    CL-USER 55 > (multiple-value-call #'list
                    (floor 5 2) (floor 7 3))
                    (2 1 2 1)

                    CL-USER 56 > (multiple-value-bind (foo0 foo1)
                    (floor 5 2)
                    (list foo0 foo1))
                    (2 1)





                    share|improve this answer


























                    • Is this an example of functional's basic lambda calculus need/tendency to curry?

                      – 147pm
                      Nov 22 '18 at 21:11











                    • @147pm: no, that's unrelated

                      – Rainer Joswig
                      Nov 22 '18 at 21:16














                    7












                    7








                    7







                    It's a general mechanism and not specific to dotimes.



                    If one calls a function or sets a variable, then only the first value will be passed:



                    CL-USER 52 > (defun foo (x) x)
                    FOO

                    CL-USER 53 > (foo (floor 5 2))
                    2

                    CL-USER 54 > (let ((foo (floor 5 2)))
                    foo)
                    2


                    To do the equivalent (calling functions, binding variables) with multiple values, one needs to use special constructs:



                    CL-USER 55 > (multiple-value-call #'list
                    (floor 5 2) (floor 7 3))
                    (2 1 2 1)

                    CL-USER 56 > (multiple-value-bind (foo0 foo1)
                    (floor 5 2)
                    (list foo0 foo1))
                    (2 1)





                    share|improve this answer















                    It's a general mechanism and not specific to dotimes.



                    If one calls a function or sets a variable, then only the first value will be passed:



                    CL-USER 52 > (defun foo (x) x)
                    FOO

                    CL-USER 53 > (foo (floor 5 2))
                    2

                    CL-USER 54 > (let ((foo (floor 5 2)))
                    foo)
                    2


                    To do the equivalent (calling functions, binding variables) with multiple values, one needs to use special constructs:



                    CL-USER 55 > (multiple-value-call #'list
                    (floor 5 2) (floor 7 3))
                    (2 1 2 1)

                    CL-USER 56 > (multiple-value-bind (foo0 foo1)
                    (floor 5 2)
                    (list foo0 foo1))
                    (2 1)






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 23 '18 at 11:27

























                    answered Nov 22 '18 at 19:21









                    Rainer JoswigRainer Joswig

                    111k8166283




                    111k8166283













                    • Is this an example of functional's basic lambda calculus need/tendency to curry?

                      – 147pm
                      Nov 22 '18 at 21:11











                    • @147pm: no, that's unrelated

                      – Rainer Joswig
                      Nov 22 '18 at 21:16



















                    • Is this an example of functional's basic lambda calculus need/tendency to curry?

                      – 147pm
                      Nov 22 '18 at 21:11











                    • @147pm: no, that's unrelated

                      – Rainer Joswig
                      Nov 22 '18 at 21:16

















                    Is this an example of functional's basic lambda calculus need/tendency to curry?

                    – 147pm
                    Nov 22 '18 at 21:11





                    Is this an example of functional's basic lambda calculus need/tendency to curry?

                    – 147pm
                    Nov 22 '18 at 21:11













                    @147pm: no, that's unrelated

                    – Rainer Joswig
                    Nov 22 '18 at 21:16





                    @147pm: no, that's unrelated

                    – Rainer Joswig
                    Nov 22 '18 at 21:16


















                    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%2f53436620%2fmultiple-return-values-of-floor-in-dotimes%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

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    Refactoring coordinates for Minecraft Pi buildings written in Python