Re: Supporting fractional values for a unit converter function

Heime <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <HfKBG_qHING1AO2xorJXK3FvVYM9rgdGkg9F8S08wk50R-OB0YGWMOng4EDH7Ve7gJN8uTT2rrd2pyTbJD8ZymqEDiHvV5CGb6E1aUKaQx0=@protonmail.com>
On Sunday, March 22nd, 2026 at 2:05 AM, Heime <[email protected]> wrote:

> I want to extend a unit conversion framework that accepts fractional
> inches by letting value be a Lisp rational (like 7/64) and then treating
> it as a normal number in the conversion.
> 
> To write (units 7/64 :inch :mm) rather than the cumbersome
> (units ((float 7) / (float 64)) :inch :mm)

Can a function be made to take an argument 7/64 and interpret 
it inside the function as (/ (float 7) (float 64))?
 
> (defun units (value from to)
>   (cond
>     ;; inches to cm
>     ((and (eq from :inch) (eq to :cm))
>        (* value 2.54))
> 
>     ;; cm to inches
>     ((and (eq from :cm) (eq to :inch))
>        (/ value 2.54))
> 
>     ;; catch invalid combinations
>     (t nil)))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.