find, starts-with, ends-with, replace
Posted: Tue Nov 11, 2008 10:48 pm
While reviewing the newLISP manual, I have noticed a function argument "natural order" puzzle for confusing newbies and frustrating oldies ;)
Given:
Find a string in text :
Okay. But starts-with (and ends-with) form is:
Shouldn't starts-with follow the find argument order?
The reason I ask is that I prototype my regex's using find. And after I optimized some old code that used find to starts-with (by simply changing the find keyword to start-with) , I had a hard time finding the problem because the code still "worked" but would not match anything!
Also, when building the string to be searched in place
"this" gets lost in the string noise... While:
Remains understandable...
And while I am "on a roll" (ranting :)
replace also suffers from "string noise" syndrome.
While this form just looks cleaner and clearer to me.
--xytroxon
Given:
Code: Select all
(setq in-my-text "this is useful")
Code: Select all
(find "this" in-my-text)
Code: Select all
(starts-with in-my-text "this")
Code: Select all
(starts-with "this" in-my-text)
Also, when building the string to be searched in place
Code: Select all
(starts-with (string in-my-text "xyz" (somestringfunc)) "this")
Code: Select all
(starts-with "this" (string in-my-text "xyz" (somestringfunc)))
And while I am "on a roll" (ranting :)
replace also suffers from "string noise" syndrome.
Code: Select all
(replace "this" (string in-my-text "xyz" (somestringfunc)) "with that")
Code: Select all
(replace "this" "with that" (string in-my-text "xyz" (somestringfunc)))