function-call notation instead of generic ref/set! Per Bothner (16 Aug 2015 18:10 UTC)
Re: function-call notation instead of generic ref/set! taylanbayirli@xxxxxx (17 Aug 2015 08:34 UTC)
Re: function-call notation instead of generic ref/set! Per Bothner (17 Aug 2015 16:39 UTC)
Re: function-call notation instead of generic ref/set! taylanbayirli@xxxxxx (18 Aug 2015 09:32 UTC)
Re: function-call notation instead of generic ref/set! Per Bothner (18 Aug 2015 16:40 UTC)

function-call notation instead of generic ref/set! Per Bothner 16 Aug 2015 18:10 UTC

I will not implement this for default-mode Kawa (i.e. not requiring
an import) because Kawa already has a cleaner and more concise notation:
Treat a vector/list/string as a pseudo-function:

#|kawa:1|# (define vec1 #(a b c d))
#|kawa:2|# (vec1 2)
c
#|kawa:3|# (define vec2 (vector-copy vec1))
#|kawa:4|# (set! (vec2 2) 'C)
#|kawa:5|# vec2
#(a b C d)
#|kawa:6|# (vec2 [3 1])
#(d b)
#|kawa:7|# (vec2 [1 <: 3])
#(b C)
#|kawa:8|# (set! (vec2 [1 <: 3]) #(k l m n o p))
#|kawa:9|# vec2
#(a k l m n o p d)

The square-bracket notation creates a vector by
evaluating the arguments, like the vector function.
However, the result is immutable, like #(...).

The [start <: end] notation creates a range, which
is like a vector of the elements in the range, but
more compactly.

In addition to (SEQ IND) indexing it also provides
selection when IND is sequence of integer indexes.
On a "left-hand-side" context (i.e. 1st argument to set!)
IND is restricted to a range.  The selected left-hand length
can  be different from the length of the replacement value,
allowed, enabling insertion/deletion.

This also works for strings:

#|kawa:1|# (define str1 (string-copy "ABCDEF"))
#|kawa:2|# (str1 2)
C
#|kawa:3|# (set! (str1 2) #\E)
#|kawa:4|# str1
ABEDEF
#|kawa:5|# (str1 [4 1 3])
EBD
#|kawa:6|# (str1 [2 <: 4])
ED
#|kawa:7|# (set! (str1 [2 <: 4]) "1234567")
#|kawa:8|# str1
AB1234567EF

[Note: these examples require the Subversion version of Kawa.]
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/