This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Question about parentheses

28 posts · 24330 views

I've just started learning lisp(bought all the little schemer books to get me going) I love the language alot, it really opens your mind about the possibilities and abstract thinking of computers. There's was just a question that's been on my mind for a while since starting. Why all the parentheses?
I mean I know what they're for but why no brackets? It seems like a symbol that would be used that much shouldn't be a two key combo. Seems like a road to carpel tunnel lol. Would it be simple to just modify a compiler of interpreter to read brackets instead of parentheses?
Else is there a faster way to type parentheses, like a way to turn off numbers for a sec or something.

Re: Question about parentheses

Well, if you look at the Space Cadet keyboards, which were used in many Lisp Machines, parentheses were where the square brackets are on most current keyboards.

Modifying the keyboard layout is fairly easy, at least on Linux. And it is even easier to redefine keys in Emacs, which is the best editor for Lisp editing. There is a Cliki page with some hints.

Brackets/Parentheses on Windows

Hey. I use Windows almost all of the time, and I was being driven mad too. I use AutoHotkey :D, and in my .ahk file, I have this:
[::
Suspend On
SendInput (){left}
Suspend Off
Return

]::
Suspend On
SendInput )
Suspend Off
Return

(::
Suspend On
SendInput []{left}
Suspend Off
Return

)::
Suspend On
SendInput ]
Suspend Off
Return

+[::
Suspend On
SendInput +[+]{left}
Suspend Off
Return
The above code swaps brackets and parentheses, and always enters the corresponding closing character along with the opening one for each type (and repositions the caret between them). I've got a bit of other general stuff in the file to, if you're interested. Even lispier :twisted:, I have replaced capslock with dash:
CapsLock::-
I originally had this:
CapsLock::Backspace
Backspace::CapsLock
but I found that I use '-' more (and there are other reasons).
blog.metalight.net

Re: Question about parentheses

Use paredit.el or something like it and you'll type half the parentheses.

Re: Brackets/Parentheses on Windows

Kohath wrote:Hey. I use Windows almost all of the time, and I was being driven mad too.
Driven mad? If you're using Windows, you must already be mad, no?

Re: Brackets/Parentheses on Windows

Paul wrote:
Kohath wrote:Hey. I use Windows almost all of the time, and I was being driven mad too.
Driven mad? If you're using Windows, you must already be mad, no?
Oh, snap!

Re: Question about parentheses

I think a lisp forum is the last place you should be bashing someone for which tools they use :lol:
______
Parenthesis are there en-masse so that it's computer readable. As for being human readable they eventually fade away and you'll just read them similarly to how your read indentation in other languages.

Re: Question about parentheses

lithos wrote:I think a lisp forum is the last place you should be bashing someone for which tools they use :lol:
Why? I could see saying that about a <choose-any-non-Lisp-language> forum...

Re: Question about parentheses

Paul Donnelly wrote:Use paredit.el or something like it and you'll type half the parentheses.
+1. Paredit rocks.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Re: Question about parentheses

Jonsul wrote:Else is there a faster way to type parentheses, like a way to turn off numbers for a sec or something.
I just had an idea: put the parens on the home row via the Mode_switch modifier. I use a custom keymap with Xmodmap, which includes this:
keycode 133 = Mode_switch
keycode 134 = Mode_switch

keycode 46 = n N parenleft
keycode 47 = s S parenright
I press either of the super keys, plus n or s, which are on the home row in the Dvorak layout. It feels better. It'll take some getting used to before it actually becomes more efficient, but I think it'll be worthwhile... maybe less so now that I'm using ParEdit and don't even have to type parenright anymore. ;)

Edit: it's been almost two weeks. I've adjusted to the change and am satisfied that it was worth the bother. I gravitated fairly easily toward super+n instead of shift+9, though mapping parenright did turn out to be a waste of a key. The benefit is not so much the easier reach as it is keeping my fingers on the home row to type in whatever comes after the paren.

Last edited by Duke on , edited 1 time in total.

"If you want to improve, be content to be thought foolish and stupid." -Epictetus

Re: Brackets/Parentheses on Windows

Mostly OT :mrgreen:
TheGZeus wrote:
Paul wrote:
Kohath wrote:Hey. I use Windows almost all of the time, and I was being driven mad too.
Driven mad? If you're using Windows, you must already be mad, no?
Oh, snap!
Quite - so far it's too hard for me to unlearn windows, especially as I don't have large amounts of time, I'm just lucky I unlearned Algol like languages. The good thing about the Autohotkey solution (just like the keyboard modmap solutions) is that it works for every other program/interface on the computer (like typing here).

I also have daydreams of designing my own operating system to get lisp closer to the metal and UI, in the spirit of Genera or Squeak, but if I tried to do that on my own I'd probably officially be classed as insane.
blog.metalight.net

Re: Brackets/Parentheses on Windows

Kohath wrote:I also have daydreams of designing my own operating system to get lisp closer to the metal and UI, in the spirit of Genera or Squeak, but if I tried to do that on my own I'd probably officially be classed as insane.
You are not the firt one to dream about that, take a look at Movitz. It seems to be quite dead by now.

Re: Question about parentheses

I use a non-standard dvorak varient called Programmers Dvorak http://www.kaufmann.no/roland/dvorak/. I further modified it by swapping 'u' and 'i', and making CAPSLOCK just a third CTRL button. My parenthesis are under keys '5' and '8', but I don't have to hold shift to get them.

This is a file I called dvorak.xmodmap, you can use it with X11 on Linux by typing "xmodmap /path/to/dvorak.xmodmap".
!
! Special programming replacements
!
keysym grave = dollar asciitilde
keysym 1 = ampersand percent
keysym 2 = bracketleft 7
keysym 3 = braceleft 5
keysym 4 = braceright 3
keysym 5 = parenleft 1
keysym 6 = equal 9
keysym 7 = asterisk 0
keysym 8 = parenright 2
keysym 9 = plus 4
keysym 0 = bracketright 6
keysym minus = exclam 8
keysym equal = numbersign grave
!
! Fairly Standard Dvorak key changes
!
!keysym equal = bracketright braceright
!keysym minus = bracketleft braceleft
keysym q = semicolon colon
keysym w = comma less
keysym e = period greater
keysym r = p
keysym t = y
keysym y = f
keysym u = g
keysym i = c
keysym o = r
keysym p = l
keysym bracketleft = slash question
keysym bracketright = at asciicircum
keysym s = o
keysym d = e
keysym f = i
keysym g = u
keysym h = d
keysym j = h
keysym k = t
keysym l = n
keysym semicolon = s
keysym apostrophe = minus underscore
keysym z = apostrophe quotedbl
keysym x = q
keysym c = j
keysym v = k
keysym b = x
keysym n = b
keysym comma = w
keysym period = v
keysym slash = z
!
! Switch Caps Lock and Control
!
remove Lock = Caps_Lock
remove Control = Control_L
keysym Caps_Lock = Control_L
add Control = Control_L
!keysym Num_Lock = Num_Lock Caps_Lock
!add Lock = Caps_Lock
Need an online wiki database? My Lisp startup http://www.formlis.com combines a wiki with forms and reports.

Re: Question about parentheses

Warren Wilkinson wrote:I use a non-standard dvorak varient called Programmers Dvorak http://www.kaufmann.no/roland/dvorak/. I further modified it by swapping 'u' and 'i', and making CAPSLOCK just a third CTRL button. My parenthesis are under keys '5' and '8', but I don't have to hold shift to get them.
I have considered learning alternate keyboard layouts many times over the years, and even switched to standard Dvorak for a month or so about 15 years ago. I always found that I had problems whenever there was another keyboard that I had to use (everything from a colleague's laptop to my own Android slider phone). A while ago, I made the decision that an alternate mapping just wasn't a big a win as I hoped. It's just too tough being a Dvorak person in a QWERTY world, at least for me. The big problem for me was that I find that I really can't hold two mappings in my head, and so any switching time really throws me off. I type very fast on QWERTY as it is, so I found that in the month I switched to Dvorak, I never got back to my QWERTY speed, and then when I switched back, it took me about a month before I was back up to my original QWERTY speed.

That said, if it works for you, very cool. There are definite advantages to Dvorak and other keyboard layouts (I'd probably learn Colemak now, for the compatibility with left-handed Ctrl-Z, -X, -C, which was a definite problem with standard Dvorak).
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Re: Brackets/Parentheses on Windows

Kohath wrote:Mostly OT :mrgreen:

I also have daydreams of designing my own operating system to get lisp closer to the metal and UI, in the spirit of Genera or Squeak, but if I tried to do that on my own I'd probably officially be classed as insane.
Well, a friend and I are in the planning stages of writing a system in a combination of Forth, Lisp, and a NeWS-like dialect of PostScript.
It's meant to run on OpenFirmware/OpenBOOT, as that gives you a biiiig standard library.
We're not ready to go into detail, but I'll be mentioning it on the forums as we get closer.

Re: Question about parentheses

findinglisp wrote:(I'd probably learn Colemak now, for the compatibility with left-handed Ctrl-Z, -X, -C, which was a definite problem with standard Dvorak).
Colemak is poesgoed.

I'm much faster, more efficient, and RSI is no longer looming over my left hand.
The Kinesis helps, too.

I got back to my QWERTY speed fairly quickly, but I had a weird, semi-hunt-and-peck way of typing that required me to look down at the kb every few words.

Re: Question about parentheses

TheGZeus wrote:
findinglisp wrote:(I'd probably learn Colemak now, for the compatibility with left-handed Ctrl-Z, -X, -C, which was a definite problem with standard Dvorak).
Colemak is poesgoed.

I'm much faster, more efficient, and RSI is no longer looming over my left hand.
The Kinesis helps, too.

I got back to my QWERTY speed fairly quickly, but I had a weird, semi-hunt-and-peck way of typing that required me to look down at the kb every few words.
So, what do you do when you have to use a QWERTY keyboard?
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Re: Question about parentheses

findinglisp wrote:
TheGZeus wrote:
findinglisp wrote:(I'd probably learn Colemak now, for the compatibility with left-handed Ctrl-Z, -X, -C, which was a definite problem with standard Dvorak).
Colemak is poesgoed.

I'm much faster, more efficient, and RSI is no longer looming over my left hand.
The Kinesis helps, too.

I got back to my QWERTY speed fairly quickly, but I had a weird, semi-hunt-and-peck way of typing that required me to look down at the kb every few words.
So, what do you do when you have to use a QWERTY keyboard?
I look at the kb about 50% of the time, and make slightly more typos, and/or type rather slowly.
Since I didn't relabel my keys I see them all the time, and Colemak really does make moving back and forth somewhat less painful than I hear Dvorak can be.
I carry my netbook everywhere so I rarely have to use other people's computers, and I'm usually much more frustrated not having things like Japanese input, tiled window management, a useful command line, and Emacs keyboard controls. Kinda hard to be worried about where keys are when it just took you minutes to figure out how to launch a program.

EDIT: To clarify, my typing is weird only on QWERTY keyboards. On Colemak I often look away from both the screen and the keyboard, and I type fairly quickly.

Re: Question about parentheses

TheGZeus wrote: EDIT: To clarify, my typing is weird only on QWERTY keyboards. On Colemak I often look away from both the screen and the keyboard, and I type fairly quickly.
That sounds reasonable. My problem is that it pretty much botched me on everything and it was painful every time I had to get it done. I really type today on QWERTY without really thinking about the keys at all. When I tried to make the switch in the past, that stopped and what was previously an unconscious act suddenly became conscious again. That really hammered my productivity.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Re: Question about parentheses

Learning a new keyboard layout requires you to do touch typing exercises all over again. While you are learning, you will feel crippled (seriously), it takes about a month of daily practice before you are comfortable with the keys. You'll still make mistakes (lots of them) but you'll now find guess and check faster than looking at your reference keyboard cheat sheet.
Need an online wiki database? My Lisp startup http://www.formlis.com combines a wiki with forms and reports.

Re: Question about parentheses

I didn't ever do touch-typing exercises, not intentionally anyway.
In fact, seeing as I'm dysgraphic, those touch-typing exercises they had me doing were systematic in a way that left me spelling things weirdly until I got off qwerty.

Re: Question about parentheses

FWIW, I tried Colemak for less than an hour last night. By the end, I could type the alphabet from a-z with only a few mistakes. Definitely easier to learn than Dvorak. Colemak has many keys matching qwerty and several easy patterns like "rst" and "jklmn"; u and y almost make sense in relation to the other keys. Not yet ready to switch (especially for passwords) but I'll try to keep practicing.

Re: Question about parentheses

Since I've posted I've discovered Racket which has "{" and "[" all equivalent to "(". Which is nice because I can use either at the same time so it allows me to organize my code more.

Re: Question about parentheses

Jonsul wrote:Since I've posted I've discovered Racket which has "{" and "[" all equivalent to "(". Which is nice because I can use either at the same time so it allows me to organize my code more.
Personally, this is a nightmare for me. When editing, you're bound to get something unbalanced and then it's a pain (either the implementation barfs or what you think is structure is suddenly untrustworthy, leading to bugs). IMO, use indentation for structure and organization, and ignore the parentheses altogether. But that's just me. There was a time when the ability to do that would have appealed to me (when I still "saw" parentheses). I understand the appeal.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Re: Question about parentheses

findinglisp wrote:
Jonsul wrote:Since I've posted I've discovered Racket which has "{" and "[" all equivalent to "(". Which is nice because I can use either at the same time so it allows me to organize my code more.
Personally, this is a nightmare for me. When editing, you're bound to get something unbalanced and then it's a pain [...]
I guess you usually can't get something unbalanced using Paredit. But this would be bad for me, too. I'm used "not to see" parenthesis, but rather to see indentation. If you alternate between {, [ and (, you'll create irregularities in the code that your brain won't ignore. Lisp code is so clean compared to other languages! Plus, the difference between { and ( is not easily seen, for instance:
)}})))})}))})

Re: Question about parentheses

gugamilare wrote:
findinglisp wrote:
Jonsul wrote:Since I've posted I've discovered Racket which has "{" and "[" all equivalent to "(". Which is nice because I can use either at the same time so it allows me to organize my code more.
Personally, this is a nightmare for me. When editing, you're bound to get something unbalanced and then it's a pain [...]
I guess you usually can't get something unbalanced using Paredit. But this would be bad for me, too. I'm used "not to see" parenthesis, but rather to see indentation. If you alternate between {, [ and (, you'll create irregularities in the code that your brain won't ignore. Lisp code is so clean compared to other languages! Plus, the difference between { and ( is not easily seen, for instance:
)}})))})}))})
Paredit is definitely the way to go, but even Paredit gets unbalanced sometimes with heavy editing and various other Emacs commands thrown in. It's much nicer to be able to fix that by just inserting a ")" somewhere, rather than having to try to figure out whether you need to balance a ")", "]" or "}". And as you rightly point out, they actually aren't very visually different (though this is somewhat font dependent and the font used in LispForum makes this worse).
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Re: Question about parentheses

Unbalanced code isn't really a problem at all. Because DrRacket automatically balances it no matter what you type. If you type "[cons 'a '(b c)" when you close cons it'll put a "]" whether you type ")" or "}". Plus the big plus to me isn't clarity in the brackets it was just a side I listed. I have a bit of carpel tunnel so the difference between a two key push vs a pinky push is big. My hand gets tired and sore after typing so many parenthesis. Plus I don't really mix brackets much anyways, the ends of my functions typically end like this:
]]]]]]

But anyways I've fixed the problem for me at least a little bit. I've created my first utility to make it easier for me, and others that are interested, to program in Common Lisp. I made Parent, give it your code file in the command-line and it converts square brackets and curly brackets into parenthesis. Also if your not interested check it out and tell me what you think. It's my first fully polished program in Scheme. It's made on linux so I'm not sure how clear it is on windows.

http://ifile.it/r7x1gtd

By the way, it's programmed in pure R6RS if you want to check out the code.