sc-im icon indicating copy to clipboard operation
sc-im copied to clipboard

user defined variables

Open 257 opened this issue 9 years ago • 26 comments

this might be because of the lack of knowledge on my part...

in old sc you couldn't define variables unless you named a cell and then used that name as named variable. lines for that definition in .sc file would start with directive 'define' and so on.

problem i have with that is that it's not dynamic because when sc writes to disk it takes variable names and replaces them with the hardcoded/statit cell address.

it would be nice to have variables define (preferebly in a seperate file which hopefully will residing in the same dir as the .sc file) with user defined variables.

let me know if what i'm saying here is vague and i will explain more.

257 avatar Feb 07 '15 16:02 257

I added a .sciminfo file where command line history is saved. It also gets read a .scimrc file in your home, before a .sc file is loaded into memory. What kind of variables do you want to define? Of what values do you want to save in those variables?

andmarti1424 avatar Feb 07 '15 18:02 andmarti1424

On Feb 07 10:03 -0800, Andr�s M. wrote:

I added a .sciminfo file where command line history is saved.

nice! where would this reside? same directory as the .sc file?

What kind of variables do you want to define? Of what values do you want to save in those variables?

constant variables so far (capital letters in k&r). non-constant variables though would be super. i can give examples if need be.

257 avatar Feb 07 '15 22:02 257

On Feb 07 17:56 -0500, SG. Garcia wrote:

On Feb 07 10:03 -0800, Andr�s M. wrote:

I added a .sciminfo file where command line history is saved.

is this pushed to github? i don't see .sciminfo being created after rebuild.

257 avatar Feb 08 '15 10:02 257

It should be in your $HOME/.sciminfo. If its not created check you define the HISTORY_FILE variable in Makefile. Going back to this issue. How do you define columns?

andmarti1424 avatar Feb 08 '15 12:02 andmarti1424

On Feb 08 04:57 -0800, Andr�s M. wrote:

How do you define columns?

(did i just say columns? scratch that, i meant columns and or rows, so following applies to both)

i can't define columns at the moment (or can i?) but if you mean how i would define columns, then i would say i would do it like defining/naming cells in sc. say for column E: define payment_by_x E

the catch is to make scim smart about column moves (insertion and deletion) so that if payment_by_x is now F because a column was inserted somewhere to the left of E, scime redefines it like so: define payment_by_x F

and references to payment_by_x throughout the .sc file won't break because of a column move.

initially i answered your question on the bug about type of variables as being constant (capital letter var names in k&r); above is a good example of a dynamic of. sorely needed in sc.

257 avatar Feb 08 '15 13:02 257

Please update to the dev branch (40b6db8d65). I restored the define tokens. Please try again the old example with the rent variable. I still have to restore them while saving a sc file.

I am afraid I do not understand how you define columns or rows, rather than just an alias of a cell. Is it supported in sc?

andmarti1424 avatar Feb 08 '15 16:02 andmarti1424

On Feb 08 08:18 -0800, Andr�s M. wrote:

Please update to the dev branch (40b6db8d65).

hopefully that's the tip/head in dev branch. i have put together an ebuild (gentoo's built system) for scim but i'm not quite good at writing ebuilds.

I restored the define tokens. Please try again the old example with the rent variable. I still have to restore them while saving a sc file. I am afraid I do not understand how you define columns or rows, rather than just an alias of a cell. Is it supported in sc?

no, no. i can't define them. that was a feature request.

257 avatar Feb 08 '15 16:02 257

OK. Please let me know when you could test it again!

andmarti1424 avatar Feb 08 '15 16:02 andmarti1424

Another thing: how would you use a defined column like: define "payment_by_x " F ??

andmarti1424 avatar Feb 08 '15 17:02 andmarti1424

On Feb 08 09:20 -0800, Andr�s M. wrote:

Another thing: how would you use a defined column like: define "payment_by_x " F ??

i posted this earlier, i have to rush out now, i will be back in 4 hours time... i can explain more then.

257 avatar Feb 08 '15 17:02 257

On Feb 08 08:52 -0800, Andr�s M. wrote:

OK. Please let me know when you could test it again!

4 hours from now.

257 avatar Feb 08 '15 17:02 257

On Feb 08 08:18 -0800, Andr�s M. wrote:

Please update to the dev branch (40b6db8d65). I restored the define tokens. Please try again the old example with the rent variable.

it works here.

257 avatar Feb 08 '15 23:02 257

On Feb 08 09:20 -0800, Andr�s M. wrote:

Another thing: how would you use a defined column like: define "payment_by_x " F ??

@nval(payment_by_x,@myrow) or @nval(@coltoa(payment_by_x),@myrow) depending on how you're gonna store those variables. i prefer the first one where payment_by_x is stored as F so there is no need to call coltoa().

257 avatar Feb 09 '15 00:02 257

On Feb 08 04:57 -0800, Andr�s M. wrote:

It should be in your $HOME/.sciminfo.

would be nice to have everything reside somewhere sensible like under ~/.config/scim/ xdg stuff...

257 avatar Feb 09 '15 00:02 257

On Feb 08 08:18 -0800, Andr�s M. wrote:

I am afraid I do not understand how you define columns or rows, rather than just an alias of a cell. Is it supported in sc?

well, on re-reading the man for sc, it is! search for 'rd' (range define). one can define a range to be a any rectangular region starting from a cell to whatever. i suppose a column or a row can easily be defined this way.

it can also be made dynamic or static (using @fixed).

i'm going to rephrase this ticket;

please make it so that named regions are shown with their names rather than their values. say rent is 340 in the example we had; as of now, at the scim's prompt, i see:

@nval(@coltoa(@mycol-1),@myrow)-340

but i rather see:

@nval(@coltoa(@mycol-1),@myrow)-rent

since that would be much it easier to read. and i think that is what would one see if looked into .sc file.

in fact if i define the column 1 before mycol as payment_by_x then we have

@nval(payment_by_x,@myrow)-rent

and if we could have named functions, say:

define @nval(payment_by_x,@myrow) what_x_paied

then we would have

what_x_paied-rent

that's as close as it gets to natural language, IMHO.

257 avatar Feb 09 '15 00:02 257

The thing is that it would be good idea that a user variable could hold not only a cell or range, but a string, an int number, a float number, a column that does not get changed with inserts or deletes of columns, a column that gets fixed and so much more.. It would be a task that take some time..

El 08/02/2015, a las 21:04, "SG. Garcia" [email protected] escribió:

On Feb 08 09:20 -0800, Andr�s M. wrote:

Another thing: how would you use a defined column like: define "payment_by_x " F ??

@nval(payment_by_x,@myrow) or @nval(@coltoa(payment_by_x),@myrow) depending on how you're gonna store those variables. i prefer the first one where payment_by_x is stored as F so there is no need to call coltoa(). — Reply to this email directly or view it on GitHub.

andmarti1424 avatar Feb 09 '15 00:02 andmarti1424

On Feb 08 16:43 -0800, Andr�s M. wrote:

The thing is that it would be good idea that a user variable could hold not only a cell or range, but a string, an int number, a float number, a column that does not get changed with inserts or deletes of columns, a column that gets fixed and so much more.. It would be a task that take some time..

100% agreed.

just a note that sc does keep track of changes to named regions. from its man page:

Commands which copy cells also modify the row and column references in affected cell expressions. The references may be frozen by using the @fixed operator or using the $ character in the reference to the cell (see below). Commands which create new rows or columns will include all newly created cells in the same ranges (named, framed, color, or those used in expressions) as their counterparts in the current row or column. This can sometimes be a significant factor when deciding whether to use ir/ic or or/oc.

257 avatar Feb 09 '15 01:02 257

On Feb 08 19:41 -0500, SG. Garcia wrote:

and if we could have named functions, say:

define @nval(payment_by_x,@myrow) what_x_paied

then we would have

what_x_paied-rent

that's as close as it gets to natural language, IMHO.

i'm going to open a ticket for 'named functions'; please merge it into this one if you see fit.

257 avatar Feb 09 '15 01:02 257

Take note that @fixed and $ operator both work in SCIM.

andmarti1424 avatar Feb 09 '15 02:02 andmarti1424

On Feb 08 18:04 -0800, Andr�s M. wrote:

Take note that @fixed and $ operator both work in SCIM.

rd doesn't. oddly enought if i define something with sc using rd and then open the same file with scim it all works... until i close the file and reopen it. all cells with definition are empty.

257 avatar Feb 09 '15 02:02 257

As I said earlier, I still have to restore them while saving a sc file. I believe this is is not initially well thought in SC, so it would be necessary to think whole thing over.

andmarti1424 avatar Feb 09 '15 02:02 andmarti1424

I forgot to say that you can make defines work like this: :int define "variablename" A2 or like this: :int define "variablename" A2:B4

they still does not get saved when you save a file..

andmarti1424 avatar Feb 09 '15 13:02 andmarti1424

Anyone else interested in this feature?? Please leave a comment and vote for it.

andmarti1424 avatar Mar 03 '17 19:03 andmarti1424

+1, definitely would love to see this feature added.

nickolasburr avatar Jul 30 '17 18:07 nickolasburr

I /think/ this feature is proposing a superset of Excel's "Named Ranges" and -- if it is -- it gets my emphatic upvote!

Have a watch of this marvellous video, especially from 12:30 (and 14:15) onwards, for some fantastic Named Range benefits :-)

jpluscplusm avatar Oct 08 '18 19:10 jpluscplusm

@andmarti1424 Please add! Also there is a typo in your documentation that needs to be fixed. In the description of @coltoa, second example is missing @ in front of a function: @nval(coltoa(@mycol-1), @myrow+1); it should be @nval(@coltoa(@mycol-1), @myrow+1) Trying that, and getting error was disheartening... seemed like implementation is buggy... please correct it & add the meaning of @mycol and @myrow & context in which they are valid... Because when I print set numeric value of @mycol & @myrow, it always evaluates to 0.00 in a cell, but seems to work well in formulae.

poetaman avatar Feb 24 '21 06:02 poetaman