Re: String to sum
Re: String to sum
- Subject: Re: String to sum
- From: Martin Orpen <email@hidden>
- Date: Wed, 13 Oct 2004 09:47:17 +0100
on 13/10/04 6:12 am, Johnny AppleScript at email@hidden wrote:
> On 04/10/12 6:38 PM, "Martin Orpen" <email@hidden> wrote:
>
>> set biglist to {}
>> set opList to {"*", "+", "/", "-"}
>> repeat 1000 times
>> set end of biglist to random number from 1 to 1000
>> set end of biglist to some item of opList
>> end repeat
>> set n to do shell script "echo \"scale=8 \n" & (biglist as string) & "1\" |
>> bc"
>> n
>
> Do you have time for a couple of questions?
>
> When I compile the above in SE 2, the last command line compiles like this:
>
> set n to do shell script "echo \"scale=8
> " & (biglist as string) & "1\" | bc"
>
> I see it's because of '/n' (newline), but I wonder, is this intentional on
> your part;i.e., did you stick that in there knowing it would compile
> visually different than written? Or does your script editor somehow not
> auto-compile that newline command?
I wrote it using "\n" in Script Debugger - so all I saw after it compiled
was a cute little square.
When I pasted it into the email it made a new line - which I thought
confusing - so I replaced it with "\n" again.
> To sort of answer my own question, I see that the newline is required to
> make the script work, but I find it a bit odd that escaping the newline
> ('\\n') breaks the script. Why is the escape character being passed? Is it
> because the core script line is enchased in double-quotes? And is this just
> a quirk that you have found the workaround for?
Unfortunately, for one-liner fans like me, bc offers a whole *environment*
and you spend more time dealing with this aspect than you do on the maths.
As I mentioned in an earlier post, I gave up on this method of using it some
time ago in favour of using a shell script that forces bc to behave in a way
that I want it to.
Here's an example of something similar (my own is a bit too nasty to post)
that is from Dave Taylor's Wicked Cool Shell Scripts:
<http://www.intuitive.com/wicked/showscript.cgi?009-scriptbc.sh>
Which allows you to get a result to two decimal places using "scriptbc -p 2"
Rolling your own shell script to increase the power of your AppleScripts is
something that I find appealing. Especially as it would be quite easy to
write the script to a temporary file, chmod it, use it and then delete it
when you've finished with it.
> I'm pleased that it works, but the compiled result just bugs me as far as
> formatting goes.
It's especially annoying when you're using stuff like sed and get lost in
all those escapes :-(
Regards
--
Martin Orpen
Idea Digital Imaging Ltd -- The Image Specialists
http://www.idea-digital.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden