Re: Minor bug: variable names with underscores

2013-03-21 Thread Harshad RJ
Pre script: Just saw John's reply while typing the below mail and most
likely this mail is of no use. I am still sending it in case it helps by
any chance.

I had a quick peek at token.cc. It looks like parse_ident() would be the
function responsible for tokenising variable names. It's core logic checks
for

std::isalnum(c) || c == '_'

It looks like it should accept (in regex):
[_a-zA-Z0-9]+

So, the problem is probably at a higher level.

-- 
*Harshad RJ* http://lavadip.com

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Minor bug: variable names with underscores

2013-03-21 Thread John Wiegley
 Harshad RJ harshad...@gmail.com writes:

 Ah, I am not familiar with commodities in ledger. So what are the variable
 names that are legal? Is there a safe way to include numbers in the names
 somehow? Numbers are required to represent invoice numbers, bill numbers,
 etc.

Alphabetic+'_' is all that I think variable names can use.  As for commodity
names, you can enclose the commodity name in double quotes.

At present variable names aren't used for much.  Can you show me an example of
where you'd want to use a bill number in a variable name?  Perhaps there's
another way (such as with metadata) to make such a usage easier for you.

John

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Minor bug: variable names with underscores

2013-03-21 Thread Harshad RJ
On Thu, Mar 21, 2013 at 6:00 PM, John Wiegley jo...@newartisans.com wrote:

 At present variable names aren't used for much.  Can you show me an
 example of
 where you'd want to use a bill number in a variable name?  Perhaps there's
 another way (such as with metadata) to make such a usage easier for you.


Example: I raise an invoice say in April 2012, and received a payment in
May 2012 with TDS (Tax deducted at source). This is how I thought I could
record it:

define TDS_RATE = 0.1

define INVOICE_1 = 1

2012/4/1
   ; Raising an invoice here
   Debtor:XYZ   INVOICE_1
   Income

2012/5/1
   ; Receiving a payment here
   BankAccout  INVOICE_1 * TDS
   Assets:TDS  INVOICE_1 * (1 - TDS)
   Debtor:XYZ

If there is a better way to do it, please let me know.

thanks,
-- 
*Harshad RJ* http://lavadip.com

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Minor bug: variable names with underscores

2013-03-21 Thread Craig Earls
RJ,
  I think I see what you are trying to do, but it will not scale the
way you are doing it.  When you have a few thousand invoices ledger
will slow to a crawl.  What about something like this:

2012/4/1   XYZ
   ; Raising and invoice
   Debtor:XYZ  1 Rs  ; Invoice: 1
   Income

2012/5/1  XYZ
; Receiving a payment here
   BankAccount  (1 Rs * TDS)  ; Invoice: 1
   Assets:TDS(1 Rs * (1 - TDS))  ; Invoice: 1
   Debtor:XYZ

You must be very careful to commoditize every number you use.  Even if
you only work in a single currency, uncommoditized numbers do not work
as you think they should in ledger.

The comments in the data above are actually meta data, the colon after
Invoice means the the value of Invoice is 1 for that posting.  You
can search on that metadata.  There is decent information in the
ledger3 manual about using metadata.  It is much faster than using
value expression all over the place.

On Thu, Mar 21, 2013 at 5:41 AM, Harshad RJ harshad...@gmail.com wrote:

 On Thu, Mar 21, 2013 at 6:00 PM, John Wiegley jo...@newartisans.com wrote:

 At present variable names aren't used for much.  Can you show me an
 example of
 where you'd want to use a bill number in a variable name?  Perhaps there's
 another way (such as with metadata) to make such a usage easier for you.


 Example: I raise an invoice say in April 2012, and received a payment in May
 2012 with TDS (Tax deducted at source). This is how I thought I could record
 it:

 define TDS_RATE = 0.1

 define INVOICE_1 = 1

 2012/4/1
; Raising an invoice here
Debtor:XYZ   INVOICE_1
Income

 2012/5/1
; Receiving a payment here
BankAccout  INVOICE_1 * TDS
Assets:TDS  INVOICE_1 * (1 - TDS)
Debtor:XYZ

 If there is a better way to do it, please let me know.

 thanks,
 --
 Harshad RJ

 --

 ---
 You received this message because you are subscribed to the Google Groups
 Ledger group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to ledger-cli+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.





-- 
Craig, Corona De Tucson, AZ
enderw88.wordpress.com

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Minor bug: variable names with underscores

2013-03-21 Thread Craig Earls
I will have to defer to John for a deeper explanation of why you must
specify a commodity, but you must.  You can specify a default
commodity with the commodity directive.  It is documented on page 27
of the ledger docs.

BTW, this all refers to ledger 3, if you are using ledger 2.6.3 all
bets are off.

On Thu, Mar 21, 2013 at 8:25 AM, Harshad RJ harshad...@gmail.com wrote:
 Thanks Craig. My intention was to only avoid repeating the number 10,000. In
 some cases (not in this specific example) I sometimes need to play with a
 value to make predictions. It is easier to do such trials by changing a
 value at a single place. I think this flexibility is one of the major
 advantages of ledger over an opaque accounting software.

 I didn't know that there was a catch with uncommonditized numbers. Can you
 please point it out to me. Is it not true that uncommoditized numbers can be
 assumed to have a default commodity of say NULL?


 thanks,
 --
 Harshad RJ

 --

 ---
 You received this message because you are subscribed to the Google Groups
 Ledger group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to ledger-cli+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.





-- 
Craig, Corona De Tucson, AZ
enderw88.wordpress.com

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Minor bug: variable names with underscores

2013-03-21 Thread John Wiegley
 Harshad RJ harshad...@gmail.com writes:

 Ok, so if I define a default commodity and then use undecorated numbers, is
 this problem solved?

No, the default commodity has nothing to do with what Ledger's internals call
simply integers.

 If so, would it be possible to modify ledger to use a pre-defined commodity
 as default?

No, because then I don't think you'd be able to use simple scalars in the ways
that you can now.

 Can an empty string be the name of the commodity?

You mean like  10?  I'm pretty sure that's allowed and makes sense.  Whether
that should be the default meaning of 10 is something else again...

Thanks for bringing up these great questions!

John

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Minor bug: variable names with underscores

2013-03-20 Thread Harshad RJ
Hi developers,

I had raised this bug a while back:
http://bugs.ledger-cli.org/show_bug.cgi?id=902

It keeps biting me once in a while. I guess this is a minor one to fix (for
someone in the know). Can you please fix it?

thanks,
-- 
*Harshad RJ* http://lavadip.com

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Minor bug: variable names with underscores

2013-03-20 Thread John Wiegley
 Harshad RJ harshad...@gmail.com writes:

 It keeps biting me once in a while. I guess this is a minor one to fix (for
 someone in the know). Can you please fix it?

This bug cannot be fixed easily in the current parser.  Since I do not do
lookahead to find the '=', or treat the 'define' directive specially,
var_name_1 is treated as a commodity with value 1, and symbol var_name_.

You will have to use fully alphabetic names, like var_name_a.  I know this
seems like a stupid oversight, but the Ledger expression language is actually
quite simplistic, and should not be considered as being on the same footing as
general purpose languages.

John

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Minor bug: variable names with underscores

2013-03-20 Thread Harshad RJ
On Thu, Mar 21, 2013 at 2:42 AM, John Wiegley jo...@newartisans.com wrote:

 This bug cannot be fixed easily in the current parser.  Since I do not do
 lookahead to find the '=', or treat the 'define' directive specially,
 var_name_1 is treated as a commodity with value 1, and symbol
 var_name_.


Do you have a lexial analyser in ledger? This sounds more like a bug with
the lexer while tokenising the input.

-- 
*Harshad RJ* http://lavadip.com

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.