How did `find` actually locate a character in a string, when it was passed a string, not a character?
I was surprised to note that find "rspq" "q"
actually found q in the series. The reason it surprised me is that the string "rpsq"
is a series of characters and I expected to have to specify "q"
as a character not as a string.
This leads to 2 questions for me:
1. how do I specify the character q
in Red?
1. why did the search succeed even though I passed in a string not a character?
red
add a comment |
I was surprised to note that find "rspq" "q"
actually found q in the series. The reason it surprised me is that the string "rpsq"
is a series of characters and I expected to have to specify "q"
as a character not as a string.
This leads to 2 questions for me:
1. how do I specify the character q
in Red?
1. why did the search succeed even though I passed in a string not a character?
red
You probably expected a functionality offind
's/same
refinement. In documentation (? find
) you can read:/same => Use "same?" as comparator.
But strangely, even withfind/same
, result is not what you would expect, despite that(same? "q" "q") = false
.
– Maciek Łoziński
Jan 19 at 15:20
2
Anyway, I think you should not ask two questions at once, and think about keeping your question's title reflect what you ask in the content.
– Maciek Łoziński
Jan 19 at 15:30
add a comment |
I was surprised to note that find "rspq" "q"
actually found q in the series. The reason it surprised me is that the string "rpsq"
is a series of characters and I expected to have to specify "q"
as a character not as a string.
This leads to 2 questions for me:
1. how do I specify the character q
in Red?
1. why did the search succeed even though I passed in a string not a character?
red
I was surprised to note that find "rspq" "q"
actually found q in the series. The reason it surprised me is that the string "rpsq"
is a series of characters and I expected to have to specify "q"
as a character not as a string.
This leads to 2 questions for me:
1. how do I specify the character q
in Red?
1. why did the search succeed even though I passed in a string not a character?
red
red
asked Jan 19 at 14:03
Terrence BrannonTerrence Brannon
1,73542448
1,73542448
You probably expected a functionality offind
's/same
refinement. In documentation (? find
) you can read:/same => Use "same?" as comparator.
But strangely, even withfind/same
, result is not what you would expect, despite that(same? "q" "q") = false
.
– Maciek Łoziński
Jan 19 at 15:20
2
Anyway, I think you should not ask two questions at once, and think about keeping your question's title reflect what you ask in the content.
– Maciek Łoziński
Jan 19 at 15:30
add a comment |
You probably expected a functionality offind
's/same
refinement. In documentation (? find
) you can read:/same => Use "same?" as comparator.
But strangely, even withfind/same
, result is not what you would expect, despite that(same? "q" "q") = false
.
– Maciek Łoziński
Jan 19 at 15:20
2
Anyway, I think you should not ask two questions at once, and think about keeping your question's title reflect what you ask in the content.
– Maciek Łoziński
Jan 19 at 15:30
You probably expected a functionality of
find
's /same
refinement. In documentation (? find
) you can read: /same => Use "same?" as comparator.
But strangely, even with find/same
, result is not what you would expect, despite that (same? "q" "q") = false
.– Maciek Łoziński
Jan 19 at 15:20
You probably expected a functionality of
find
's /same
refinement. In documentation (? find
) you can read: /same => Use "same?" as comparator.
But strangely, even with find/same
, result is not what you would expect, despite that (same? "q" "q") = false
.– Maciek Łoziński
Jan 19 at 15:20
2
2
Anyway, I think you should not ask two questions at once, and think about keeping your question's title reflect what you ask in the content.
– Maciek Łoziński
Jan 19 at 15:30
Anyway, I think you should not ask two questions at once, and think about keeping your question's title reflect what you ask in the content.
– Maciek Łoziński
Jan 19 at 15:30
add a comment |
2 Answers
2
active
oldest
votes
- Consult the official reference documentation.
- Functions in Red are highly polymorphic.
find
can either search for a given element or a first occurence of sub-series.
add a comment |
- Characters are values of
char!
type, and are specified like this:c: #"q"
. - I'd say it's because Red tries to copy behavior of Rebol. And in Rebol's documentation you can find this example:
probe find "here and now" "and"
"and now"
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%2f54267883%2fhow-did-find-actually-locate-a-character-in-a-string-when-it-was-passed-a-str%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
- Consult the official reference documentation.
- Functions in Red are highly polymorphic.
find
can either search for a given element or a first occurence of sub-series.
add a comment |
- Consult the official reference documentation.
- Functions in Red are highly polymorphic.
find
can either search for a given element or a first occurence of sub-series.
add a comment |
- Consult the official reference documentation.
- Functions in Red are highly polymorphic.
find
can either search for a given element or a first occurence of sub-series.
- Consult the official reference documentation.
- Functions in Red are highly polymorphic.
find
can either search for a given element or a first occurence of sub-series.
edited Jan 19 at 15:14
answered Jan 19 at 14:47
92149214
35817
35817
add a comment |
add a comment |
- Characters are values of
char!
type, and are specified like this:c: #"q"
. - I'd say it's because Red tries to copy behavior of Rebol. And in Rebol's documentation you can find this example:
probe find "here and now" "and"
"and now"
add a comment |
- Characters are values of
char!
type, and are specified like this:c: #"q"
. - I'd say it's because Red tries to copy behavior of Rebol. And in Rebol's documentation you can find this example:
probe find "here and now" "and"
"and now"
add a comment |
- Characters are values of
char!
type, and are specified like this:c: #"q"
. - I'd say it's because Red tries to copy behavior of Rebol. And in Rebol's documentation you can find this example:
probe find "here and now" "and"
"and now"
- Characters are values of
char!
type, and are specified like this:c: #"q"
. - I'd say it's because Red tries to copy behavior of Rebol. And in Rebol's documentation you can find this example:
probe find "here and now" "and"
"and now"
answered Jan 19 at 15:09
Maciek ŁozińskiMaciek Łoziński
445613
445613
add a comment |
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%2f54267883%2fhow-did-find-actually-locate-a-character-in-a-string-when-it-was-passed-a-str%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
You probably expected a functionality of
find
's/same
refinement. In documentation (? find
) you can read:/same => Use "same?" as comparator.
But strangely, even withfind/same
, result is not what you would expect, despite that(same? "q" "q") = false
.– Maciek Łoziński
Jan 19 at 15:20
2
Anyway, I think you should not ask two questions at once, and think about keeping your question's title reflect what you ask in the content.
– Maciek Łoziński
Jan 19 at 15:30