简体   繁体   中英

How do I fix error: RuntimeException Unmatched delimiter: )

The problem is that if I pass this function (in my REPL) with 08 or 09, it will give me an error.

I've tried removing parenthesizes around to see if the error would go away.

(defn format-pump-number [number]
  (if (.contains (str number) "0")
    (str number)
    (str "0" number))
    (if (> number 9)
      (if (< number 100)
        (str number)
        (throw (Exception. "Dispenser number can only be 2 characters!"))))
      (str "0" number))

I expect [number] to be returned 08 or 09 when passed that exact number.

Computers usually interpret a number like 08 or 09 to be octal, which is an error since octal digits only go from 0..7. Historically, it was thought that using a leading zero character 0 was a clever type of code, since the character 0 looks like the character O from the word Octal . So, when the compiler sees an integer starting with a 0 , it is interpreted to mean "The digits coming next should be interpreted in base-8, not base-10". Example:

 12  =>  twelve (parsed using base-ten)
012  =>  ten    (parsed using base-eight)

This attempt to be overly clever causes problems through today, as you have discovered.

So, it is not your function at all, just a bad error message. Observe:

(println "val=" 8) => `val= 8`

but

(println "val=" 08)
  => Error refreshing environment: Syntax error reading source at (tst/demo/core.clj:19:20).

I do not get an error message regarding "Unmatched delimiter", so I'm not sure how that arose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM