News for hackers. Stuff that matters.
Re:Does anybody find this Scheme code readable? by ApplaudPumice on Saturday February 27, 2016 @07:33PM (#11189167)
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?

Re:Does anybody find this Scheme code readable? by EdwardCoffin on Saturday February 27, 2016 @07:53PM (#11189229)
Perhaps this is (at least) a 4th possibility, which is that it would take you time to get used to, but once you had it would not be too much for you. Even Paul Graham (enthusiastic Lisp advocate) once said "I suppose I should learn Lisp, but it seems so foreign" [1]

I found it reasonably readable. The only criticism I had, offhand, was that the predicates like 'is-piece-knight?' were a bit verbose: the query mark at the end is understood to label a predicate, so the 'is-piece-' was redundant. I'd have written 'knight?' instead. That's pretty nit-picky though, and I don't think the current convention really detracts from its readability.

[1] If Lisp is So Great: http://paulgraham.com/iflisp.html

Re:Does anybody find this Scheme code readable? by electronvolt on Saturday February 27, 2016 @08:01PM (#11189254)
1. From glancing at it: this is a pretty ugly solution.

On the plus side: It's minimal and doesn't spend much time building abstractions on top of the basic lists/etc. that scheme provides. However, it certainly isn't pretty.

For instance: Things like the king & knight checks are really pretty ugly brute force solutions.

Similarly, the variable & function naming really is rather unclear and very poorly commented--some of that may be use of things idiomatic to scheme that I'm unfamiliar with though.

2. Always a possibility, I certainly don't know you. ;)

3. Some people certainly have said that before and probably will again. This is really just a personal preference thing, I think.

Re:Does anybody find this Scheme code readable? by hacker_9 on Saturday February 27, 2016 @07:38PM (#11189183)
I'd probably start by putting this in an editor with syntax highlighting, which should make things a bit clearer. I'm from the C world myself, but I could mostly follow along the code. It's s-expressions of course though, which take some getting used to. Personally I hate them, so I stay away!
Re:Does anybody find this Scheme code readable? by mkozlows on Saturday February 27, 2016 @07:52PM (#11189222)
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.

Re:Does anybody find this Scheme code readable? by cbd1984 on Saturday February 27, 2016 @07:58PM (#11189248)
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.

Re:Does anybody find this Scheme code readable? by cbd1984 on Saturday February 27, 2016 @07:53PM (#11189225)
4. You best read code by trying it out and seeing what pieces of it do.

Try it with an interpreter running.

Re:Does anybody find this Scheme code readable? by inopinatus on Saturday February 27, 2016 @07:55PM (#11189235)
4. The syntax is unfamiliar.