Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have EXISTS? return the type field or none instead of true/false. #612

Closed
Siskin-Bot opened this issue Feb 15, 2020 · 0 comments
Closed
Labels
CC.resolved Issue with CureCode status built, tested or complete Oldes.resolved Bugs/wishes with Oldes' fixes/features Test.written Type.wish

Comments

@Siskin-Bot
Copy link
Collaborator

Submitted by: BrianH

EXISTS? as it is now can only be used as a logical predicate, telling you whether the file exists. However, the underlying QUERY function also returns whether the file is a file or a directory in the type field of the returned info object. Instead of throwing away that information, return it. This would save us from having to run QUERY again inside the DIR? function to get that info back. Additional QUERY calls can have measurable overhead on networked resources.

If we change the code in EXISTS? from [found? attempt [query target]] to [select attempt [query target] 'type] then EXISTS? will return the type of the file as a word if it exists, but none if it doesn't. This will allow EXISTS? to still be used in logical predicate situations (except AND and OR), while providing more info to those who need it.

EXISTS? not working with AND and OR is not likely to be a problem as most programmers use EXISTS? with ALL or ANY instead. You can still use FOUND? if you need a logic! value.

; Old usage
if exists? %something [do something]
unless all [exists? f not dir? f] [error handling]

; New usage
if exists? %something [do something]
unless 'file = exists? f [error handling]

Imported from: CureCode [ Version: alpha 33 Type: Wish Platform: All Category: n/a Reproduce: Always Fixed-in:alpha 37 ]
Imported from: metaeducation#612

Comments:

Rebolbot commented on Feb 11, 2009:

Submitted by: BrianH

This would also be a good candidate for the R2-Future backports, as the underlying code would be quite different between R2 and R3. Which means that the equivalent replacement code would need a lot of special casing, due to the changes in QUERY and DIR?. This change would make it easier to write code that will run on R2 and R3.

Implemented in mezz-file 575 and r2-forward 574.


Rebolbot added the Type.wish on Jan 12, 2016


@Siskin-Bot Siskin-Bot added the CC.resolved Issue with CureCode status built, tested or complete label May 22, 2020
@Oldes Oldes added Test.written Oldes.resolved Bugs/wishes with Oldes' fixes/features labels Dec 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CC.resolved Issue with CureCode status built, tested or complete Oldes.resolved Bugs/wishes with Oldes' fixes/features Test.written Type.wish
Projects
None yet
Development

No branches or pull requests

2 participants