Page 1 of 2
sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 2:04 am
by triantaresX
Hello all,
Sorry to ask (maybe) a simple question but I apparently cannot find an answer to a (not so minor) niggle I'm having.
My first app I created was based on older python app I once made....took me half a day to discover that counting from 1 instead of 0 in lists was what was killing my math, BTW.
The app requires a lot of user input with floating points. Being European the locale here is to use a , as a decimal indicator.
Generally I used (on my Linux box) sed to simply substitute . for , with sed: 's/\./,/g before working on the input.
Most people using the app will be from the (post Brexit) EU and thus prone to mindlessly stumbling on this , versus . thingy.
Of course I can still induce "sed" in a shell but that would hamper Windows users without a bash implementation.
I can't imagine I'm the only one encountering this so I hope someone can point me in the right direction.
Thanks in advance.
'
Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 2:46 am
by stam
Hi triantaresX,
Probably wouldn't generalise the comma as decimal indicator to 'europe' -- i know this is the norm in places like Greece, but not sure which other countries use this!
If all you want to do is replace "." with "," you can do this with:
Code: Select all
replace "." with "," in someVariable
or
Code: Select all
put replaceText(someVariable, ".", comma) into someVariable
hope that helps,
Stam
Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 3:10 am
by dunbarx
If, as Stam mentioned, all you need is to transform one decimal "style" to another, then he nailed it with the "replace" command.
For general use, I would write a function and keep it somewhere. The reason for this is simple. It is possible that you do not want to replace every comma with a period in whatever data you have to deal with.
A lot depends on where you get your arguments from. Maybe in the form of a pair of variables, or, perhaps a pair of fields:
Code: Select all
on mouseUp
answer commaToDec(fld 1) + commaToDec(fld 2)
end mouseUp
function commaToDec arg
replace comma with "." in arg
return arg
end commaToDec
Of course, this may be overkill, but at least is robust.
Craig
Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 8:16 am
by Davidv
ReplaceText uses regular expression pattern matching so you will be on familiar ground from Perl. It will, for example, enable you to make sure you replace only those commas which are between digits, for a little security. If you know there can be no erroneous matches then Replace is quite a bit faster.
Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 10:25 am
by triantaresX
thanks for the replies ..... "replace" looks like the best candidate for ease albeit a reusable function is a good solution too.
Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 10:30 am
by richmond62
i know this is the norm in places like Greece
Pretty well trans-European, well, except the Republic of Ireland.
As far as I know the only place in geographical Europe where '.' is used for a decimal point
is Britain (which, after all, is no longer in political Europe).
Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 12:31 pm
by triantaresX
The simplest global solution for me turned out use replace on the numerical fields.
This is works as long as no-one uses a dot for 1000 values.
Code: Select all
on mouseLeave
replace "," with "." in me
end mouseLeave
on keyDown or Up made the input reverse from right to left while typing in the field --- haven't looked up why, yet.
Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 12:36 pm
by triantaresX
Let's not forget Ireland is still in the EU and uses the Anglo Saxon format.
on historyUp
From what I searched, found out the Scott Payne opted for a decimal dot where later Leibniz wanted to use the dot as multiplier in place of x. So he introduced the comma.
end historyUp
It's a total mess.
Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 3:33 pm
by stam
Yeah i looked it up properly and it is a mess indeed! I stand corrected...
Weirder still that some countries use other symbols... you'd think a basic math convention like this would have become universal...
But then again facebook has shown us that even simple things like operator priority in a mathematical equations (left-to-right priority vs. parentheses > multiplication/division > addition/subtraction) vary tremendously.
We're pretty useless

Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 4:15 pm
by richmond62
I have a book about farm accounting from 1760
and it took me a very long time indeed to work out that what was meant by 'X'
in that book was 'ADD'.
But on the other hand, this thing about what is called the 'arbitrariness of the sign' and the need for shared codes runs
through everything.
И може би Ти ще има проблеми не само с езица, и с азбуки, нали?
Hence the reason why people get their knickers in a twist any time they encounter a way of representing things with which
they are not familiar. Earlier today someone was trying to tell me that 'crisps' were 'chips', or was it the other way round . . . but I digress.
-

- chips.jpeg (11.75 KiB) Viewed 6668 times
-
One man's chips are another man's "Freedom Fries."

Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 5:24 pm
by FourthWorld
triantaresX wrote: ↑Sun Jan 31, 2021 2:04 am
My first app I created was based on older python app I once made....took me half a day to discover that counting from 1 instead of 0 in lists was what was killing my math, BTW.

A LiveCode developer and a Python developer walk into a bar. The LiveCode developer was able to convince the Python developer to buy everyone's first round, since he thought he was giving away zero.
Generally I used (on my Linux box)...
Which distro do you use? I'm an Ubuntu fanboy myself.
Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 5:27 pm
by bogs
richmond62 wrote: ↑Sun Jan 31, 2021 4:15 pm
One man's chips are another man's "Freedom Fries."
Oh, is THAT what they were saying! I thought it was 'Free dem fries...' and I kept saying 'Too late, they is already ate...'

Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 8:07 pm
by triantaresX
Which distro do you use? I'm an Ubuntu fanboy myself.
I make happy use of Elive Beta; Buster based with a modernized E16 desktop. Amazingly fast, stable and easily customized to the core.
I stopped using Ubuntu once they fazed out their Unity desktop and switched over to Elive but I'm also very impressed with Manjaro's Plasma Desktop on my PinebookPro that runs arm64...... so no Livecode apps there.
A long time ago I tried out Runrev (it came with one of the Linux magizine CDs IIRC) but didn't really have time to get in too deep. Then a while ago I stumbled over the Userguide PDF (2010) on a backup disc, wondered what had become of it and once found as Livecode, decided to give it a renewed effort..... especially with the Community versions (I've got +) available now.
Up to now I'm liking what I'm seeing, albeit Community+ 9-6-1 (forum doesn't allow dots here

) version does get jittery sometimes but hasn't crashed yet. Despite having to change some habits and needing the userguide and dictionaries at hand a lot.
Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 8:11 pm
by bogs
triantaresX wrote: ↑Sun Jan 31, 2021 8:07 pm
(forum doesn't allow dots here

)
3 more posts, and that will pass

Re: sed equivalent for Livecode all
Posted: Sun Jan 31, 2021 9:14 pm
by stam
triantaresX wrote: ↑Sun Jan 31, 2021 8:07 pm
A long time ago I tried out Runrev (it came with one of the Linux magizine CDs IIRC) but didn't really have time to get in too deep.
Yeh similar for me too - i picked this up originally about 7 years ago but was too busy/never got into it/other stuff had priority, had a brief encounter with in again about 4 years ago but never got into then either - it was too different from the environment i was using at the time and i couldn't get my head round it.
About 6 months ago i picked it up in earnest and am now a convert. It does need some getting used to at first but there are so many conveniences its incredible compared to other languages. I've not yet hit any significant limitations/showstoppers (i'm sure i will at some point), so i'm happy so far.
And the community (and forum) is an incredible resource
