1. question about find function

euphoria 4.0.5 Windows 10

This one gets me every now and then. Something I am not seeing but for the life of me...
Yes, match() works.
Any thoughts would be appreciated.

include std/console.e 
 
sequence haystack = "just in time" 
object needle = "in" 
printf (1,"location = %d\n",eu:find(needle,haystack)) 
any_key("<cr>") 


Returns a zero, meaning not found.

From the documentation:

8.15.2.1 find

<built-in> function find(object needle, sequence haystack, integer start)

Find the first occurrence of a "needle" as an element of a "haystack", starting from position "start"..
Parameters:

needle : an object whose presence is being queried
haystack : a sequence, which is being looked up for needle
start : an integer, the position at which to start searching. Defaults to 1.

Returns:

An integer, 0 if needle is not on haystack, else the smallest index of an element of haystack that equals needle.

new topic     » topic index » view message » categorize

2. Re: question about find function

Yes, you're looking for match() not find(). There is a fundamental difference in how these work.

The find() function locates an item in a sequence, and with strings each character is an atom that is an item in the sequence, so you're looking for atoms.

? find( 'D', "ABCDEF" ) 
4 
 
? find( "D", "ABCDEF" ) 
0 

The match() function locates a matching subset of a sequence, and so with strings you're looking a partial string match in a larger string.

? match( 'D', "ABCDEF" ) 
-- crashes, expects 'D' to be a sequence 
 
? match( "D", "ABCDEF" ) 
4 
 
? match( "BCD", "ABCDEF" ) 
2 

And you would use find() to locate a string in a sequence of strings, since those strings are items in the sequence.

? find( "DEF", {"ABC","DEF","GHI"} ) 
2 

Hope this helps.

P.S. I agree the documentation needs work. I've asked for help contributing updates and corrections to the documentation. Anyone who wants to offer corrections is free to submit pull requests on GitHub: https://github.com/OpenEuphoria/euphoria/pulls.

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: question about find function

ghaberek said...

Yes, you're looking for match() not find(). There is a fundamental difference in how these work.

The find() function locates an item in a sequence, and with strings each character is an atom that is an item in the sequence, so you're looking for atoms.

...

The match() function locates a matching subset of a sequence, and so with strings you're looking a partial string match in a larger string.

...

P.S. I agree the documentation needs work. I've asked for help contributing updates and corrections to the documentation. Anyone who wants to offer corrections is free to submit pull requests on GitHub: https://github.com/OpenEuphoria/euphoria/pulls.

-Greg

Years ago, i wrote my own routines, that work as i expect them to. I am not here to work for and fit into the language, but vice versa.

It's strange to see you use the word "strings", it was such a dirty word that began many flame wars on the old forum. Perhaps now match() can be aliased to strfind() ? Well, maybe not, that will find only sub-matches, not equivalences. Must be a reason somewhere....

Github doesn't work for me on windoze. I am not going to install *nix and spend a weekend downloading and debugging *nix packages so i can use yet another google product (github). Making the acquisition of OE more difficult doesn't help. Have you noticed how many $millions Julia has raked in in the 10 years it's been in existance?

Kat

new topic     » goto parent     » topic index » view message » categorize

4. Re: question about find function

Thanks. Somewhat clearer. find() seems to be closer to equals() as it disallows sequences that are longer but may contain the needle. The key is, I think, "item". {"needle"} is a sequence containing one item. "needle" is a sequence containing 6 items. Oh well, back to sleep. I'll surely get caught out again in a year or so.

new topic     » goto parent     » topic index » view message » categorize

5. Re: question about find function

katsmeow said...

Years ago, i wrote my own routines, that work as i expect them to. I am not here to work for and fit into the language, but vice versa.

I think of programming as a craft and like any other craft, there are general-purpose tools and specific-purpose tools, and it's up to the crafts-person to determine which is best suited for the task at hand. And the best crafts-people will often find they need to build their own tools when they've reached the limits of what others have provided. And whenever we do that, it shows we're growing and improving our craft.

katsmeow said...

It's strange to see you use the word "strings", it was such a dirty word that began many flame wars on the old forum.

I know, and I remember seeing some of those conversations. I may have even taken to adding to the flames. But I think that we need to de-stigmatize language like "strings" or anything else that may have resulted from the pedantry and gate-keeping of the past. If it looks like a string, swims like a string, and quacks like a string, then it probably is a string. Let's just call it a string, even if the underlying representation of the data is something else.

katsmeow said...

Perhaps now match() can be aliased to strfind() ? Well, maybe not, that will find only sub-matches, not equivalences. Must be a reason somewhere....

I think I'd avoid any similarly-named "str" functions in Euphoria. I am still constantly confused by the subtle differences of strcmp, strpos, substr, instr, in languages like C and PHP. What's worse is some of those functions have the same name but slightly-different behaviors. In Euphoria, find() finds, match() matches, compare() compares, reverse() reverses. Even if I do find it normal to call them "strings" we need to keep in mind that underneath the strings we are still working with the versatility of sequences. Although, thinking about it now, I suppose adding a specific string library with C/PHP-alike functions might be helpful for porting other code and easing the transition of newcomers to the language.

katsmeow said...

Github doesn't work for me on windoze.

Can you not install Git, or does it not work when you try to use it? What version of Windows are you on? There's a portable version that doesn't require an actual install: https://git-scm.com/download/win. You should be able to just extract that into a local directory and then add the "bin" directory it to your PATH.

katsmeow said...

I am not going to install *nix and spend a weekend downloading and debugging *nix packages

And I wouldn't expect you to. Personally, I'm still trying to sort out all of the required packages to complete a full-release build of OpenEuphoria, which is at least part of the reason why it hasn't happened yet. I can build the core executables over and over again but a lot of the other tools and documentation still elude me.

katsmeow said...

so i can use yet another google product (github).

Git is a source code versioning tool originally developed by Linus Torvalds, the creator of Linux. GitHub is a website for hosting Git-based projects owned by Microsoft. (GitHub was an independent company until its acquisition in 2018.) At the time, I was apprehensive but optimistic and so far I think it's been going well. Git is the most-used code versioning tool by a very wide margin and GitHub is the largest host of public Git repositories. And I realize this may sound like an ad populum fallacy, but I believe that to remain relevant to world, we at least have to try to exist in the same venue as the rest of the world.

katsmeow said...

Making the acquisition of OE more difficult doesn't help.

The last thing I want to do is keep anyone out of anything or make it more difficult to get or do things. Acquiring the code itself doesn't require Git, and I'm sorry if I suggested that was the only way forward. If you click the Code button on the project page, you can select "Download ZIP" to get a complete copy of the repository as-is. It doesn't even come with the .git directory, just the code. If you want to contribute any changes then make them and then email me a zip file of the files and I'll do the necessary diff'ing and git'ing to merge the changes.

katsmeow said...

Have you noticed how many $millions Julia has raked in in the 10 years it's been in existance?

I'm painfully aware of how popular younger languages like Juila, Go, Rust, and Swift have become in the past ten years. Even languages as old as Euphoria, like Python, Ruby, and Lua have all gained quite a massive following, much much larger than we have here. And I think Euphoria better than all of those. But those languages have all found adoption via large corporations or communities needing a scratch a specific itch and either inventing the language to solve it (Swift: Apple, Rust: Mozilla, Go: Google) or have injected serious money or resources into the language (Python: education/engineering, Ruby: web development, Lua: game development). We need to scratch an itch.

-Greg

new topic     » goto parent     » topic index » view message » categorize

6. Re: question about find function

jessedavis said...

Thanks. Somewhat clearer. find() seems to be closer to equals() as it disallows sequences that are longer but may contain the needle. The key is, I think, "item". {"needle"} is a sequence containing one item. "needle" is a sequence containing 6 items. Oh well, back to sleep. I'll surely get caught out again in a year or so.

This may help, for any object x and sequence s (Humpf, this hasn't quite ended up as clear as I thought it would...)

object x sequence s integer i 
x = '1' s = "1234"              -- experiment here 
--x = "1" s = {"1","2"}         -- (maybe like so) 
 
i = find(x,s) 
 
if i=0 then 
    printf(1,"not found\n") 
else 
    printf(1,"s[i]=x: %t\n",s[i]=x) 
end if 
 
x = "23"                        -- comment this line in/out 
--x = {"2"}                     -- (or this for above maybe) 
 
i = match(x,s) 
 
if i=0 then 
    printf(1,"no match\n") 
else 
    if atom(x) then 
        printf(1,"s[i]=x: %t\n",s[i]=x) -- same as find() case 
    else 
        printf(1,"s[i..i+length(x)-1]=x: %t\n",s[i..i+length(x)-1]=x) 
    end if 
end if 

The above is Phix: for Euphoria replace the %t with %d (and get 1/0 instead of true/false).
In particular note that when x is not an atom, find() and match() behave quite differently.
What throws people, I think, is they are quite similar when x is an atom.

Perhaps slightly simpler, consider i=match('b',"abc") vs. i=match("b","abc"), both set i to 2.
In the first case, "abc"[2]=='b', same as find, in the second it is "abc"[2..2]=="b", with find a no-show.

One golden rule is that checking whether a string is a substring of another string is always match() and never find().

new topic     » goto parent     » topic index » view message » categorize

7. Re: question about find function

ghaberek said...

We need to scratch an itch.

So true.

ghaberek said...

I'm still trying to sort out all of the required packages to complete a full-release build of OpenEuphoria, which is at least part of the reason why it hasn't happened yet.
I can build the core executables over and over again but a lot of the other tools and documentation still elude me.

There may be an irony in there somewhere...

new topic     » goto parent     » topic index » view message » categorize

8. Re: question about find function

petelomax said...
ghaberek said...

I'm still trying to sort out all of the required packages to complete a full-release build of OpenEuphoria, which is at least part of the reason why it hasn't happened yet.
I can build the core executables over and over again but a lot of the other tools and documentation still elude me.

There may be an irony in there somewhere...

I assure you the irony is not lost on me. blink

-Greg

new topic     » goto parent     » topic index » view message » categorize

9. Re: question about find function

Re: strings
I do indeed respect and use the heck out of sequences , especially when the task is to munge strings. I use them as linked-list-metadata, and as chunks corresponding to screen line lengths or other length-restricted situations, or as color holders, etc..

ghaberek said...

We need to scratch an itch.

-Greg

I think the other way around : OE needs a better list of scratchers. The url i gave for Julia was to it's enviable list of features. While OE has some of those, arguing against more features in OE just because a few people won't use them is like saying everyone uses all the functions available in Julia. I think it's unlikely you will find all the itches out there, and then build and advertise the new scratcher, but likely someone with an itch is looking for a unique scratcher no one has.

It's like the type system hack i did. I used it firstly as sharing variables with other processes, but it's also useful as a on_var_set() function, which can alert-signal other functions or processes that some condition has changed (and how, possibly by who), which is a feature some popular languages have. And surely you noticed the existing type system in OE doesn't supply the name of the variable it's type testing? But suggest such features be added to OE here and the auditorium goes silent, sets their seat on fire, and walks out. This blows my mind.

Kat

new topic     » goto parent     » topic index » view message » categorize

10. Re: question about find function

I was going to speechify about why the newer languages attract money vs OE, like was it their lack of desireable features vs OE's lack of desireable features? No...... but i'll leave it up to you to remember why OE lacks the features which mainstream programmers seem to want.

Kat

new topic     » goto parent     » topic index » view message » categorize

11. Re: question about find function

katsmeow said...

I was going to speechify about why the newer languages attract money vs OE, like was it their lack of desireable features vs OE's lack of desireable features? No...... but i'll leave it up to you to remember why OE lacks the features which mainstream programmers seem to want.

This statement indicates to me that you think the current lack of progress is due to some unwillingness by one or more people to actually implement features. You know that's not true, right?

Sure, when Rob was running the language he was stringent about what things he implemented and where he put his time and effort. And that was his prerogative; he was selling Euphoria as a commercial product and it was his product to do with as he intended, for better or worse.

But this, the OpenEuphoria Group, it's what we have now (or what little of it is left) and this has never been about that. Sure, I think we need to be critical about what things we add, and in some cases we may have been too critical or maybe not critical enough. Any progress this group has made in the past thirteen years has been the result of individuals with no commercial interest in the project contributing the things they wanted to see implemented by virtue of their own time and effort.

Simply put: OpenEuphoria lacks mainstream features because no one has taken the time to implement them. That's all there is to it.

-Greg

new topic     » goto parent     » topic index » view message » categorize

12. Re: question about find function

ghaberek said...

Simply put: OpenEuphoria lacks mainstream features because no one has taken the time to implement them. That's all there is to it.

-Greg

Over the years, i have deleted task_msgs , deleted three versions of irc.e , and most recently deleted shared_vars. I deleted dynamic loading and unloading of dll files, which could have been used as pseudo-threads or string execution. This proves your statement is incorrect: the problem is not lack of time.

With the archives locked at Feb 2018 and set to read-only, there's not even a link on this site to submit contributions. Is that growth? I am taking the time to point this out, will i be villified again for pointing out the areas OE needs to improve?

Kat

new topic     » goto parent     » topic index » view message » categorize

13. Re: question about find function

katsmeow said...

This proves your statement is incorrect: the problem is not lack of time.

Well my issue, personally, is absolutely a lack of time. It's the number one thing I lack right now and you'd see more output from me if I had more time.

katsmeow said...

With the archives locked at Feb 2018 and set to read-only, there's not even a link on this site to submit contributions. Is that growth?

Growth is not relevant to the RDS website. That content belongs to Rob Craig and I have agreed host it for him as-is. It is not mine to do with as I wish. You're welcome to reach out to him directly if you'd like to see that change. I can provide access to the web host for that website to whomever Rob might agree to let work on it.

If you're looking for somewhere to host new Euphoria-related content then you will not find it on this website. I've considered it in the past but I think we've moved beyond the need for hosting on individual websites when there are so many good websites dedicated to that purpose. I suggest using Github, but you could also use Bitbucket, Gitlab, Sourceforge, etc. Then post a new topic on this forum to let everyone know about it. We can even post it to the news section for added visibility.

katsmeow said...

will i be villified again for pointing out the areas OE needs to improve?

Do you feel like you're being vilified? I haven't had intentions anywhere near that. I apologize if it seemed that way. You're absolutely correct that things need to improve and I value your input.

-Greg

new topic     » goto parent     » topic index » view message » categorize

14. Re: question about find function

ghaberek said...

If you're looking for somewhere to host new Euphoria-related content then you will not find it on this website.

I can't express how sorry i am to hear that. It seems the things OE is not keeps growing longer.

ghaberek said...
katsmeow said...

will i be villified again for pointing out the areas OE needs to improve?

Do you feel like you're being vilified? I haven't had intentions anywhere near that. I apologize if it seemed that way. You're absolutely correct that things need to improve and I value your input.

-Greg

My appologies for the misunderstanding, i did not mean by you. I often wished i could help.

Kat

new topic     » goto parent     » topic index » view message » categorize

15. Re: question about find function

One of the factors that attracted me to Euphoria in 2007 was the site with an Archive of programs and other Euphoria sites. Yes, I still download libraries there. Now it is quite difficult to find new programs/libraries. OE reminds me of the Linux community, A lot of programs for Euphoria/OE I just couldn't run, either demanding libraries that weren't included, or swearing at existing ones. Forgive my clumsy language, it's Google Translate's fault

new topic     » goto parent     » topic index » view message » categorize

16. Re: question about find function

AlexXX said...

One of the factors that attracted me to Euphoria in 2007 was the site with an Archive of programs and other Euphoria sites. Yes, I still download libraries there. Now it is quite difficult to find new programs/libraries. OE reminds me of the Linux community, A lot of programs for Euphoria/OE I just couldn't run, either demanding libraries that weren't included, or swearing at existing ones. Forgive my clumsy language, it's Google Translate's fault

katsmeow said...

I often wished i could help.

You could always help out on the archives/PCAN. There are 2000+ entries that have not been tested recently, some not for more than two decades.
Which are genuinely complete trash, which need a few minor tweaks, which run on 4.1 or Phix and with what dependencies or other setup requirements?
Some examples:
http://phix.x10.mx/pmwiki/pmwiki.php?n=Main.Diamond-liteObjectOrientedLibrary - I uploaded a phix-compatible version, and marked it with [[!phix]]
You could also start adding [[!eu41]] tags (I may or may not need to do a little admin to get that all working nicely and correctly)
http://phix.x10.mx/pmwiki/pmwiki.php?n=Catagory.Rejected - many of those were unfairly marked [[!rejected]] because of the DOS tag
They could all be tried/reworked with http://phix.x10.mx/pmwiki/pmwiki.php?n=Main.DosRescueForPhix or the Eu 4.1 version of that
Like http://phix.x10.mx/pmwiki/pmwiki.php?n=Main.TwinsGame add a [[!broken]] tag if you've conceded defeat, or for that matter
sift through http://phix.x10.mx/pmwiki/pmwiki.php?n=Catagory.Broken looking for things you can fix, or want fixing

If you or anyone else are going to work on PCAN then before you start read http://phix.x10.mx/pmwiki/pmwiki.php?n=Main.Introduction
PCAN is a wiki. It is meant for the likes of you (yes, you) to edit and improve.

new topic     » goto parent     » topic index » view message » categorize

17. Re: question about find function

Q: How can I just delete a listing from pcan?

Example: links to very old versions of EuGTK - there is no reason anyone would want to use old buggy versions, and links are bad, some of those ISP's have long ago gone out of business.

new topic     » goto parent     » topic index » view message » categorize

18. Re: question about find function

irv said...

Q: How can I just delete a listing from pcan?

Example: links to very old versions of EuGTK - there is no reason anyone would want to use old buggy versions, and links are bad, some of those ISP's have long ago gone out of business.

In some cases it might be better to mark the entry as [[!superceded]] and link to the latest version, to avoid older links (to pcan) such as those on this forum going dead.
Likewise when a page on pcan contains a dead link it is usually better just to mark it as such, say old link: [@[[http://edita.is-great.org/]]@], and maybe [[!rejected]] or [[!broken]]
Note that in the past I have encountered dead links on pcan, asked here, and been pleasantly surprised and delighted to have been furnished with replacements from people's private copies.
In other cases it is totally acceptable to simply replace the entire page contents, especially if you are the original author.

Obviously if you blank out or vandalise a page, it is part of wiki-culture that any other average user can restore it. True deletion is admin-only.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu