Multiple return values of floor in dotimes
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
add a comment |
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
add a comment |
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
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
common-lisp floor multiple-value
edited Nov 23 '18 at 9:34
coredump
21.3k33046
21.3k33046
asked Nov 22 '18 at 18:41
147pm147pm
582416
582416
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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)
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 22 '18 at 18:48
Silvio MayoloSilvio Mayolo
14.1k22453
14.1k22453
add a comment |
add a comment |
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)
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
add a comment |
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)
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
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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