guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cannot compile: srfi-10 define-reader-ctor 'hash '#,(


From: Taylan Ulrich Bayirli/Kammer
Subject: Re: cannot compile: srfi-10 define-reader-ctor 'hash '#,(
Date: Thu, 14 Aug 2014 13:13:27 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Marko Rauhamaa <address@hidden> writes:

> Panicz Maciej Godek <address@hidden>:
>
>> Using dictionaries is programmers' daily bread, yet Scheme has no
>> common way for doing that (unlike Perl, PHP, Python, JavaScript,
>> Clojure and other popular languages).
>
> I disagree. S-expressions far surpass whatever the others have to offer.
>
>
> Marko

To be fair, when your read syntax makes dictionaries explicit, you get
an additional bit of "safety" in your program because if you receive a
dictionary where a list was expected then the list-ref will error and
make the problem surface, whereas if you get an alist you can list-ref
it and have the program keep running a bit farther (maybe to the end,
producing wrong output).

(I've been bitten by this in PHP once where associative arrays are also
just arrays and some stupid web interface delivered me a single assoc
array where it should have delivered an array with one assoc array in
it.)

On the other hand, if you just implement full validation which walks
your input and turns all expected alists into suitable record types
(think DTD) then it's about equally safe either way I guess.  That is
the ideal long-term solution, validating most of your input as soon as
it's received, and preventing silly mistakes like typos in alist keys
because instead you use accessor procedures on records.

All in all, having to use alists for hash tables can be an annoyance
when you don't use eager input validation; it forces you to use extra
alist->hash-table and hash-table->alist calls where you could otherwise
just read and write an object if all it contains is lists, vectors, and
hash tables, and it can cause some bugs to remain hidden for longer.

Taylan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]