sed equivalent for Livecode all

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

triantaresX
Posts: 6
Joined: Sun Jan 31, 2021 1:45 am

sed equivalent for Livecode all

Post by triantaresX » Sun Jan 31, 2021 2:04 am

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. :-P

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.
'

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: sed equivalent for Livecode all

Post by stam » Sun Jan 31, 2021 2:46 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: sed equivalent for Livecode all

Post by dunbarx » Sun Jan 31, 2021 3:10 am

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

Davidv
Posts: 77
Joined: Sun Apr 09, 2006 1:51 am

Re: sed equivalent for Livecode all

Post by Davidv » Sun Jan 31, 2021 8:16 am

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.

triantaresX
Posts: 6
Joined: Sun Jan 31, 2021 1:45 am

Re: sed equivalent for Livecode all

Post by triantaresX » Sun Jan 31, 2021 10:25 am

thanks for the replies ..... "replace" looks like the best candidate for ease albeit a reusable function is a good solution too.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: sed equivalent for Livecode all

Post by richmond62 » Sun Jan 31, 2021 10:30 am

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).

triantaresX
Posts: 6
Joined: Sun Jan 31, 2021 1:45 am

Re: sed equivalent for Livecode all

Post by triantaresX » Sun Jan 31, 2021 12:31 pm

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.

triantaresX
Posts: 6
Joined: Sun Jan 31, 2021 1:45 am

Re: sed equivalent for Livecode all

Post by triantaresX » Sun Jan 31, 2021 12:36 pm

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.

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: sed equivalent for Livecode all

Post by stam » Sun Jan 31, 2021 3:33 pm

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 :wink:

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: sed equivalent for Livecode all

Post by richmond62 » Sun Jan 31, 2021 4:15 pm

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
chips.jpeg (11.75 KiB) Viewed 6659 times
-
One man's chips are another man's "Freedom Fries." 8)

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10048
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: sed equivalent for Livecode all

Post by FourthWorld » Sun Jan 31, 2021 5:24 pm

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. :-P
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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: sed equivalent for Livecode all

Post by bogs » Sun Jan 31, 2021 5:27 pm

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...' :twisted:
Image

triantaresX
Posts: 6
Joined: Sun Jan 31, 2021 1:45 am

Re: sed equivalent for Livecode all

Post by triantaresX » Sun Jan 31, 2021 8:07 pm

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. :D

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. :mrgreen:

Up to now I'm liking what I'm seeing, albeit Community+ 9-6-1 (forum doesn't allow dots here :shock: ) 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.

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: sed equivalent for Livecode all

Post by bogs » Sun Jan 31, 2021 8:11 pm

triantaresX wrote:
Sun Jan 31, 2021 8:07 pm
(forum doesn't allow dots here :shock: )
3 more posts, and that will pass :D
Image

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: sed equivalent for Livecode all

Post by stam » Sun Jan 31, 2021 9:14 pm

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 ;)

Post Reply