Lisp HUG Maillist Archive

Reading with #\, as decimal point?

Does anyone on the list know if there is a standard idiom for reading 
where #\, is interpreted as the decimal point, e.g. such that I get

CL-USER> (read-from-string "1,2")
1.2
3
CL-USER>

Thanks in advance.

-Klaus.


Re: Reading with #\, as decimal point?

On Mon, 2007-06-11 at 16:24 +0200, Klaus Harbo wrote:
> Does anyone on the list know if there is a standard idiom for reading 
> where #\, is interpreted as the decimal point, e.g. such that I get
> 
> CL-USER> (read-from-string "1,2")
> 1.2
> 3
> CL-USER>

If you are attempting to read numeric values then  CL-L10N might provide
what you need.

<http://common-lisp.net/project/cl-l10n/docs/cl-l10n_3.html#SEC6>

(parse-number "1,2" "sv_SE") 
=> 1.2

Sean.

-- 
....Please don't assume Lisp is only useful for Animation and Graphics,
AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor
applications, Expert Systems, Finance, Intelligent Agents, Knowledge
Management, Mechanical CAD, Modeling and Simulation, Natural Language,
Optimization, Research, Risk Analysis, Scheduling, Telecom, and Web
Authoring just because these are the only things they happened to list.

Kent Pitman.



Re: Reading with #\, as decimal point?

Unable to parse email body. Email id is 6749

Re: Reading with #\, as decimal point?

> Does anyone on the list know if there is a standard idiom for  
> reading where #\, is interpreted as the decimal point, e.g. such  
> that I get

If your requirements are just to accomplish what you described above,  
you can use straight Lisp.  It doesn't get much simpler:

(defun rfs (string)
   (read-from-string (substitute #\. #\, string)))


> CL-USER> (read-from-string "1,2")
> 1.2
> 3

Cl-USER 291 > (rfs "1,2")
1.2
3

Chhi'mèd




Re: Reading with #\, as decimal point?

Klaus Harbo wrote:
> Does anyone on the list know if there is a standard idiom for reading
> where #\, is interpreted as the decimal point, e.g. such that I get
> 
> CL-USER> (read-from-string "1,2")
> 1.2
> 3
> CL-USER>
> 
> Thanks in advance.
> 
> -Klaus.

http://groups.google.de/group/comp.lang.lisp/msg/062d10be57ce7a2f

-jens


Updated at: 2020-12-10 08:45 UTC