Array or char bug?

Started by cameyo, September 23, 2020, 03:21:42 AM

Previous topic - Next topic

cameyo

I have some problem to update an array:
; define an array
(setq ar (array 256 '(-1)))
; define a string
(setq str "bar")
; define an index
(setq idx (char (str 0)))
;-> 98
(number? idx)
;-> true
; update array
(setf (ar idx) 555)
;-> 555
(number? (char (str 0)))
;-> true
; update array fail
(setf (ar (char (str 0))) 555)
;-> ERR: string expected : 555


Why the last expression raise an error?

cameyo

#1
Reading the manual for "char" function...

This solve the problem (on UTF-8 enabled system):
(setf (ar (char (str 0) 0 true)) 555)
;-> 555