SliTaz SliTaz Forum

You are not logged in.

#1 2012-07-16 00:29:45

lexeii
Administrator
Registered: 2012-03-21
Posts: 1,853

Nimrod lessons: Q&A

Hi,

Who can answer me how to use named variables in subexes? There are examples:

1. Numbered variables:

[c]subex"My name is $1, I'm $2 years old." % [ "Aleksej", "36" ][/c]

2. Named variables:

[c]subex"My name is $name, I'm $age years old." % [ ? ? ? ][/c]

Offline

#2 2012-07-16 06:34:56

Trixar_za
Administrator
Registered: 2011-03-29
Posts: 1,506

Re: Nimrod lessons: Q&A

I think named variables might have a bug in subexes.

Example:

[c]echo subex"My name is $name, I'm $age years old." % ["Aleksej", "36"][/c]

will return [c]My name is Aleksej, I'm Aleksej years old.[/c]

While the following works like expected:

[c]echo subex"My name is $name, I'm $2 years old." % ["Aleksej", "36"][/c]

Edit: Araq said he's working on a solution to this, so it should be on github soon tongue

Offline

#3 2012-07-16 08:58:38

lexeii
Administrator
Registered: 2012-03-21
Posts: 1,853

Re: Nimrod lessons: Q&A

Hi Brenton,

Thank you for contacting Araq! wink

Interesting, what is future syntax of this feature.

I think it will be useful for parsing shell conf files. Like this:

Conf file:

VarA="123"

VarB="abc$VarA"

VarC="$VarB.tar.gz"

Nimrod code:

Read line by line,

split line to variable name and its value,

assign value to variable,

if value contain '$' then execute subex with new variable's name and all known variables.

Offline

#4 2012-07-16 12:53:52

Trixar_za
Administrator
Registered: 2011-03-29
Posts: 1,506

Re: Nimrod lessons: Q&A

In the future it may be done like this:

[c]$&"See here: $variable and some more here: $rubbish" % ["Tada!", "Ok?"][/c]

Also a present: http://www.trixarian.net/downloads/aporia-0.1.2.tazpkg - Yep, it's the Nimrod based IDE with syntax highlighting included. Should make editing nimrod code easier.

Offline

#5 2012-07-16 13:37:22

lexeii
Administrator
Registered: 2012-03-21
Posts: 1,853

Re: Nimrod lessons: Q&A

I think, better will be like a tuple: [variable:"Tada!", rubbish:"Ok?"]

because variable's order can change. And maybe I want to add more variables to the right side, while left side contains less items.

For what I need it -- see above.

Still unusable for my goals. Maybe I can write code, but big and uneffective...

I've compiled Aporia too. But my Aporia frequently hangs, have no 'Close' or 'Exit' entry in 'File' menu, and sometimes don't close own window by pressing on cross. Killall helps. I want to test your pkg.

And what about Nimrod official SliTaz's receipt (in wok-undigest, I think). Brenton, can you write this receipt? I'm not familiar with cooker and receipts, what about you?

Offline

#6 2012-07-16 14:05:58

Trixar_za
Administrator
Registered: 2011-03-29
Posts: 1,506

Re: Nimrod lessons: Q&A

subexes were designed so that the order of the variables don't matter. You can order them within the string or even do them in reverse order if you feel like it.

For Aporia, it's down to how you compile it. The readme file is wrong. To make it work without weird bugs, you need to compile it with nimrod c -d:release - any other way breaks it. That's how I compiled the one I packaged tongue

A receipt for it would be tricky since you need a nimrod package first. Also the download link with regards to github is also weird.

Offline

#7 2012-07-16 14:15:53

lexeii
Administrator
Registered: 2012-03-21
Posts: 1,853

Re: Nimrod lessons: Q&A

Hmm. How compiler can guess which variable I mean in the right part of subex? I can write there any strings or variables...

...and will first named variable in the left part is assigned to the first entry in the right part, and so on. Right?

In this case using of numbered variables ($3, $1, $[true|false]2 and so on) gives me more flexible access to result.

Offline

#8 2012-07-16 14:40:12

Trixar_za
Administrator
Registered: 2011-03-29
Posts: 1,506

Re: Nimrod lessons: Q&A

It can tell using references like it explains in the table @ http://nimrod-code.org/subexes.html

Mind you, plain old strutils should also have a similar level of flexibility.

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.016 seconds, 7 queries executed - Memory usage: 1.54 MiB (Peak: 1.77 MiB) ]