Re: booleans...
Re: booleans...
- Subject: Re: booleans...
- From: Jean-Christophe Helary <email@hidden>
- Date: Tue, 20 Mar 2018 14:41:28 +0900
> On Mar 20, 2018, at 14:25, Stan Cleveland <email@hidden> wrote:
>
> On Mar 19, 2018, at 10:02 PM, Jean-Christophe Helary
> <email@hidden <mailto:email@hidden>>
> wrote:
>>
>> What I want, as I wrote earlier, is a way to coerce any statement to boolean
>> values instead of having to add try block everywhere. Either a statement
>> returns a value and it is true, or it returns an error (or nil) and it is
>> false
>
> Okay, this approach is a bit ugly, because requires your "any statement" to
> be converted to a properly-escaped AS string, like so:
Thank you very much.
I guess run script is the closest AS thing to the Lisp "eval" command we'll
ever have. The escaping is ugly, but the idea is beautiful...
So I guess I'm on my way to create a handler that properly escapes an
expression into an AS string... :-)
Jean-Christophe
>
> alias ("" & (path to desktop) & "not.there")
> becomes:
> "alias (\"\" & (path to desktop) & \"not.there\")"
>
> Then, it uses run script to either convert that string to a valid AS result
> or return false:
>
> on myBoolean(myExpression)
> try
> set theResult to run script myExpression
> on error
> set theResult to false
> end try
> return theResult
> end myBoolean
>
> myBoolean("alias (\"\" & (path to desktop) & \"not.there\")")
> --> false
> myBoolean("alias (\"\" & (path to desktop) & \"is.there\")")
> --> alias "MacHD:Users:stanc:Desktop:is.there"
> myBoolean("\"hello\" as integer")
> --> false
> myBoolean("45.6 as integer")
> --> 46
> myBoolean("\"45.6\" as integer")
> --> 46
>
> As I said, it's ugly.
>
> Stan C.
Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden