4 ms·
amazed to see there are people who find myObject.myMethod(x, y, z); easier to read than (my-function x y z) - that's 2 delimiters in Clojure vs 6 in your C-
by vbuwivbiu 8y ago
amazed to see there are people who find
myObject.myMethod(x, y, z);
easier to read than
(my-function x y z)
- that's 2 delimiters in Clojure vs 6 in your C-style language
- zeveb 8y agoIn fairness, it'd actually be: (my-method my-object x y z) But yes, the Lisp version is so much clearer to me. I just don't get why it's not more popular.
- vbuwivbiu 8y agoor (object-as-namespace/my-function x y z) still fewer delimiters and less noise
- trevor-e 8y agoHow does this work with autocomplete if you need to know the method name before the object you're working with? Maybe I'm not getting something but that sounds incredibly painful to use in practice.
- jimbokun 8y agoBecause idiomatic Clojure code is based on functions and not methods. The method call syntax is just there to support interop with Java.
- zeveb 8y agoIn Common Lisp, it works because symbols are scoped by package, not by object. So if you're in the package foo and start typing 'bar,' then your editor would autocomplete symbols in the foo package starting with 'bar'; likewise if you typed 'baz:quux' your editor autocomplete would autocomplete symbols in the baz package starting with 'quux.' Common Lisp most definitely doesn't have one namespace; this is really nice in practice.
- trevor-e 8y agoOK so my confusion was from thinking Clojure is statically typed, which apparently is not true. I was basically asking the same question as https://www.reddit.com/r/Clojure/comments/6f6cq2/how_to_compensate_for_clojures_lack_of_dot/ https://www.reddit.com/r/Clojure/comments/6f6cq2/how_to_comp...
- davnicwil 8y agoTo me the delimiters help with readability by breaking up the statement into its component parts in a visual way that I can immediately parse. Before even reading the variable names I understand the role of each in the statement.
- vbuwivbiu 8y agoyou only used 2 delimiters to say that
- kazinator 8y agoTXR Lisp: myobject.(mymethod x y.w z.bar) Notations can be useful. Most Lispers reach for 'expr rather than (quote expr). Rational numbers could look like #R(1 2) but CL has 1/2 instead. I decided on a dot notation for object access because OOP is used to organize the program as a whole; so it's not some small thing like arithmetic. The dot notation integrates into Lisp; it doesn't disturb the syntax with ambiguities and reads/prints cleanly, and corresponds to structure in several straightforward ways: a.b.c -> (qref a b c) .a.b.c -> (uref a b c) There must not be whitespace: a . b is the consing dot, which can only appear at the end of the list. Of course, if a and b are 3 and 2, we get 3.2 which is a floating-point token; and that mustn't be glued to something else. 1> '(qref a b c) a.b.c 2> '(qref a b (qref c)) (qref a b (qref c)) 3> '(qref a (qref b c)) (qref a b.c) 4> 3.2.a expr-4:1: trailing junk in floating-point literal: 3.2.a ** syntax error 5> '(qref a (b c) d (e) (f g)) a.(b c).d.(e).(f g) There are qref and uref macros which do useful things with the notation. E.g. 14> (stat "args.h") #S(stat dev 2049 ino 670288 mode 33204 nlink 1 uid 500 gid 500 rdev 0 size 5628 blksize 4096 blocks 16 atime 1540848391 mtime 1524635813 ctime 1524635813 path "args.h") 15> (mapcar [chain stat [juxt .path .size]] (glob "*.h")) (("args.h" 5628) ("arith.h" 2270) ("buf.h" 3712) ("cadr.h" 2515) ("combi.h" 1517) ("config.h" 2644) ("debug.h" 3762) ("dict.h" 4373) ("eval.h" 3898) ("ffi.h" 5146) ("filter.h" 2298) ("ftw.h" 1492) ("gc.h" 2370) ("glob.h" 1485) ("hash.h" 3412) ("itypes.h" 3238) ("lib.h" 37442) ("lisplib.h" 1680) ("match.h" 2031) ("parser.h" 4597) ("rand.h" 1798) ("regex.h" 3204) ("signal.h" 7954) ("socket.h" 1460) ("stream.h" 8553) ("struct.h" 3475) ("strudel.h" 1486) ("sysif.h" 2747) ("syslog.h" 1998) ("termios.h" 1436) ("txr.h" 1885) ("unwind.h" 9880) ("utf8.h" 2590) ("vm.h" 1681) ("vmop-ORIG.h" 1660) ("vmop.h" 2008) ("y.tab.h" 4542)) Example OOP code that is full of the notation is found in the compiler: http://www.kylheku.com/cgit/txr/tree/share/txr/stdlib/compiler.tl http://www.kylheku.com/cgit/txr/tree/share/txr/stdlib/compil... I feel I have come up with a successful design: a way of integrating the dot selection notation into a Lisp dialect without losing "Lispiness".