
Does anybody find this Scheme code readable? - ApplaudPumice
https://raw.githubusercontent.com/pratyakshs/Che.ss/master/check.ss
======
jsnell
I don't think this is code that someone learning Scheme should be reading,
it's pretty damn unreadable. Some obvious issues, just starting from the top
and continuing for a while:

\- Defining a new iteration macro FOR that's used in just a single function,
has a very odd syntax, and that's way too generic for uses.

\- The first parameter to the PICK function (the position) is a pair. That
might make sense if those pairs were values that had been passed throughout
the program. But actually every place where PICK is called constructs a
totally new pair just for that call. It should be split to separate ROW and
COLUMN parameters. This would remove a lot of noise at the call sites.

\- Or alternatively, if the parameter is kept as is, all of this boilerplate:
(cons (- (car kpos) 1) (- (cdr kpos) 1)) should be replaced by calls to a
function that does both the consing, caring and cdring. Something like (add-
to-position kpos -1 -1)

\- The is-piece-foo functions use eq? and equal? inconsistently.

\- The CH-HOF function is full of copy-paste boilerplate with each instance
having tiny tweaks. Turning these into calls to sensibly parametrized
functions would make a big difference.

\- There's like 20 instances of (set! rsc (+ rsc 0)) . What in the world is
that supposed to achieve?

\- The indentation of IFs is horrible. Putting the THEN branch on the same
line as the test, and then putting the ELSE on the next line is just criminal.
Especially given how deeply nested some of the condition expression are, it's
very hard to notice that it's in fact a two-branch rather than one-branch IF.
It's as if this code was deliberately written to be obfuscated.

------
aaronbrethorst
It's been about 15 years[1] since I last spent a lot of time with Scheme, but
yes. As others have mentioned, the author could've done a better job with
variable names, and syntax highlighting would do a world of good, but the code
itself looks pretty understandable.

If you're not using DrRacket, then please start using it. I learned what was
then Scheme from SICP[2], but I've heard that the Little Schemer is perhaps a
bit more approachable. Try starting with it[3].

[1] That moment when you realize it's been over fifteen years since you
started college...Yeesh.

[2]
[https://en.wikipedia.org/wiki/Structure_and_Interpretation_o...](https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs)

[3] [http://stackoverflow.com/questions/13003850/little-
schemer-a...](http://stackoverflow.com/questions/13003850/little-schemer-and-
racket)

------
elliotec
Quite, yeah.

But if the author's goal was maximum readability, they might have considered
doing away with the abbreviations.

------
anaphor
Yes, although I'm not sure why they had to use single letter symbols to
identify the different types of chess pieces. Also it seems like they could've
applied the DRY principle a bit with all of those conditionals. Also the use
of set! is a little bit ugly.

------
S4M
I can somewhat make sense of that code, but the code of function ch-hof is a
bit hard to read - and the function name is not helping. I guess he's trying
to see if the king is under check, and if so by which piece(s).

Also I notice code like:

    
    
        (- (cdr kpos) 1))
    

How is that possible? If kpos is a list of two elements to represent the
king's position, so (cdr kpos) should be a list, not compatible with
subtraction.

For example:

    
    
        #;4> (- (cdr '(1 2)) 1)
    
        Error: (-) bad argument type: (2)

~~~
gus_massa
The lists are made of cons, but you can make arbitrary trees with cons.

After looking carefully, the _kpos_ is the result of the function _find_. In
this case it's a cons with the row and the column of the king. So the code
that runs is more like

    
    
      (define kpos (cons 1 2))
      (- (cdr kpos) 1)
    

In this case, for clarity I prefer to use a struct instead of a cons to save
the position

    
    
      (struct cell (row col))
      (define kpos (cell 1 2))
      (- (cell-col kpos) 1)

------
adwf
Yep, although I only use Common Lisp, this is still readable to me.

A couple of things could be improved for me; I almost never use abbreviated
variable names unless it's for simple iteration.

Also things like this being repeated on 8 lines, just screams for some sort of
abstraction:

    
    
      (set! rsc (+ rsc 3)) (set! rsc (+ rsc 0))) (set! rsc (+ rsc 0))

------
Grue3
I don't find it readable. I immediately see a lot of repetition, which means
an opportunity for helper functions/macros. However the so-called "hygienic
macros" in Scheme seem pretty confusing to me. I prefer non-hygienic macros
like in Lisp.

My biggest Scheme program is [1]. I wrote it years ago, but I can still read
it. Using sanely named variables is key.

[1]
[https://github.com/tshatrov/scriptfu/blob/master/animstack.s...](https://github.com/tshatrov/scriptfu/blob/master/animstack.scm)

------
kogir
Looks fine to me, though I tend to write my lisp narrower and taller. Part of
that is breaking long argument lists out onto multiple lines with proper
indentation.

Here's some Racket code in DrRacket:
[http://i.imgur.com/GKveHtl.jpg](http://i.imgur.com/GKveHtl.jpg)

You get used to it pretty quickly, and good editors will provide paren
matching and completion.

------
ApplaudPumice
I want to learn scheme but that is too much for me. So either

1\. That is badly written code. 2\. I'm a bad programmer. 3\. Scheme's syntax
is ugly.

What do you think?

~~~
mkozlows
I think "it's hard to read code in a language you don't know."

You're fooled on this because so many languages are so similar -- if you know
C++, you can trivially read Java and C# and Python, and even languages that
are a bit further afield like Javascript and Perl still are heavily influenced
by C, so don't seem too odd.

But Scheme is a whole new family of languages. It's like being an English
reader and looking at Greek text as opposed to Spanish. It's not that Greek is
harder than Spanish, it's that Spanish is closer to what you already know.

~~~
cbd1984
People say this and it's not really true.

Scheme has mutable state. Scheme has unmarked side-effects. Scheme has
variables, as opposed to tags applied to constant values.

Scheme was an entirely new kind of language back when lambda expressions were
Heavy Deep Magic and dynamic typing was something you did when your
Flexowriter was well-oiled (hyperbole intentional). These days, it's no
weirder than Javascript or the more modern dialects of Java or Visual C#.Net.
Hell, even C++ is getting lambdas and closures, and that's a Serious Business
COBOL-Replacement Language.

Modern Algol dialects _are_ Scheme in everything except syntax, and now that
metaprogramming (Ruby, to begin with) is beginning to catch on, I fully expect
language designers to re-invent some shambolic version of s-expressions when
they realize that metaprogramming in Algol syntax is _hard_.

Scheme _won_. It's just that its victory was suppressed for political reasons.

------
jiyinyiyong
I will always hate parentheses there. So mine:

![]([https://pbs.twimg.com/media/CcT4B8MUMAAiuvK.jpg:large](https://pbs.twimg.com/media/CcT4B8MUMAAiuvK.jpg:large))

------
msie
Yes

------
lispm
No, the code looks ugly.

