| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#41
| |||
| |||
| QUOTE What CL has is optional type declaration and runtime check. Qi implements static type-checking and type-inference, and besides other functional-paradigm features. But it abandons prefix-notation and multi-paradigm approach as a whole. UNQUOTE Actually Qi is prefix - just like Lisp. Mark |
|
#42
| |||
| |||
| Mark Tarver wrote: > Actually Qi is prefix - just like Lisp. > I'm not convinced. You've got quite infixy pattern match and type declaration syntax IIRC, and it's pretty ubiquitous. Okay, it's always localised within toplevel-prefix forms like (datatype ...) and (define ...), and there's plenty of precedent in lisp for such localised-infixy things, but qi code seems to have more infix than I at least am totally comfortable with. type declarations are particularly unlispy looking. Sure, they might macro-map to end-user-usable lispier syntax underneath (I haven't really looked), but if so, you still encourage the infixy stuff as "idiomatic" qi. e.g. (from memory, might not be quite valid or meaningful qi) (define blah foo -> bar ) not (define blah (-> foo bar)) X : A ; ======= X : B ; not (<=> ((/- X A)) ((/- X B))) etc. |
|
#43
| |||
| |||
| On 31 Aug, 05:11, David Golden <david.gol...@oceanfree.net> wrote: > Mark Tarver wrote: > > Actually Qi is prefix - just like Lisp. > > I'm not convinced. *You've got quite infixy pattern match and type > declaration syntax IIRC, and it's pretty ubiquitous. > > Okay, it's always localised within toplevel-prefix forms like > (datatype ...) and (define ...), and there's plenty of precedent in > lisp for such localised-infixy things, but qi code seems to have more > infix than I at least am totally comfortable with. *type declarations > are particularly unlispy looking. > > Sure, they might macro-map to end-user-usable lispier syntax underneath > (I haven't really looked), but if so, you still encourage the infixy > stuff as "idiomatic" qi. > > e.g. (from memory, might not be quite valid or meaningful qi) > > (define blah > * * * * foo -> bar ) > > not > > (define blah > * *(-> foo bar)) > > X : A ; > ======= > X : B ; > > not > > (<=> ((/- X A)) > * * *((/- X B))) > > etc. Its entirely up to you (define foo [X | Y] -> Y) (define foo (cons X Y) -> Y) are both legal. Mark |
|
#44
| |||
| |||
| On Aug 31, 4:35 pm, Mark Tarver <dr.mtar...@ukonline.co.uk> wrote: > > > Actually Qi is prefix - just like Lisp. > (define foo > (cons X Y) -> Y) what about the arrow? ![]() |
|
#45
| |||
| |||
| Mark Tarver wrote: > Its entirely up to you > > (define foo > [X | Y] -> Y) > > (define foo > (cons X Y) -> Y) > > are both legal. > Uhm. And the '->' still sitting infix between its lhs and rhs in both of the above ? |
|
#46
| |||
| |||
| On 31 Aug, 17:14, David Golden <david.gol...@oceanfree.net> wrote: > Mark Tarver wrote: > > Its entirely up to you > > > (define foo > > * [X | Y] -> Y) > > > (define foo > > * (cons X Y) -> Y) > > > are both legal. > > Uhm. And the '->' still sitting infix > between its lhs and rhs in both of the above ? C:\Documents and Settings\User\Desktop\Qi II\Qi 9.2>lisp.exe -M lispinit.mem sta rtup.txt Qi 2007, Copyright (C) 2001-2007 Mark Tarver www.lambdassociates.org version 9.2 (Turbo-E) (0-) (define unlispy-rule [Arrow Patterns Result] -> (append Patterns [Arrow Result])) unlispy-rule (1-) (define mapcan _ [] -> [] F [X | Y] -> (append (F X) (mapcan F Y))) mapcan (2-) (define macroexpand [define F | Rules] -> [define F | (mapcan unlispy-rule Rules)] X -> X) WARNING: DEFUN/DEFMACRO: redefining function macroexpand in C:\Documents and Settings\Use r\Desktop\Qi II\Qi 9.2\startup.txt, was defined in C:\Documents and Settings\Use r\Desktop\Qi II\Qi 9.2\Qi 9.2.txtmacroexpand (3-) (define factorial (-> (0) 1) (-> (X) (* X (factorial (- X 1))))) factorial (4-) (factorial 6) 720 I think the moral here is - be careful of what you wish for. Mark |
|
#47
| |||
| |||
| On Aug 31, 7:39 pm, Mark Tarver <dr.mtar...@ukonline.co.uk> wrote: > On 31 Aug, 17:14, David Golden <david.gol...@oceanfree.net> wrote: > > > Mark Tarver wrote: > > > Its entirely up to you > > > > (define foo > > > [X | Y] -> Y) > > > > (define foo > > > (cons X Y) -> Y) > > > > are both legal. > > > Uhm. And the '->' still sitting infix > > between its lhs and rhs in both of the above ? > > C:\Documents and Settings\User\Desktop\Qi II\Qi 9.2>lisp.exe -M > lispinit.mem sta > rtup.txt > > Qi 2007, Copyright (C) 2001-2007 Mark Tarverwww.lambdassociates.org > version 9.2 (Turbo-E) > > (0-) (define unlispy-rule > [Arrow Patterns Result] -> (append Patterns [Arrow Result])) > unlispy-rule > > (1-) > (define mapcan > _ [] -> [] > F [X | Y] -> (append (F X) (mapcan F Y))) > mapcan > > (2-) > (define macroexpand > [define F | Rules] -> [define F | (mapcan unlispy-rule Rules)] > X -> X) > > WARNING: > DEFUN/DEFMACRO: redefining function macroexpand in C:\Documents and > Settings\Use > r\Desktop\Qi II\Qi 9.2\startup.txt, was defined in C:\Documents and > Settings\Use > r\Desktop\Qi II\Qi 9.2\Qi 9.2.txtmacroexpand > > (3-) (define factorial > (-> (0) 1) > (-> (X) (* X (factorial (- X 1))))) > factorial > > (4-) (factorial 6) > 720 > > I think the moral here is - be careful of what you wish for. > > Mark And with this new macroexpand, will all other Qi 'machinery' work as previously? Is there an 'idiomatic way' to program in Qi (I mean from your point of view -- I understand, that anyone is free to do what he likes) and does this prefix pattern matching variant align with the idiomatic way? Thanks, Vsevolod |
|
#48
| |||
| |||
| On 31 Aug, 20:09, Vsevolod <vselo...@gmail.com> wrote: > On Aug 31, 7:39 pm, Mark Tarver <dr.mtar...@ukonline.co.uk> wrote: > > > > > > > On 31 Aug, 17:14, David Golden <david.gol...@oceanfree.net> wrote: > > > > Mark Tarver wrote: > > > > Its entirely up to you > > > > > (define foo > > > > * [X | Y] -> Y) > > > > > (define foo > > > > * (cons X Y) -> Y) > > > > > are both legal. > > > > Uhm. And the '->' still sitting infix > > > between its lhs and rhs in both of the above ? > > > C:\Documents and Settings\User\Desktop\Qi II\Qi 9.2>lisp.exe -M > > lispinit.mem sta > > rtup.txt > > > Qi 2007, Copyright (C) 2001-2007 Mark Tarverwww.lambdassociates.org > > version 9.2 (Turbo-E) > > > (0-) (define unlispy-rule > > * * * * [Arrow Patterns Result] -> (append Patterns [Arrow Result])) > > unlispy-rule > > > (1-) > > (define mapcan > > * _ [] -> [] > > * F [X | Y] -> (append (F X) (mapcan F Y))) > > mapcan > > > (2-) > > (define macroexpand > > * [define F | Rules] -> [define F | (mapcan unlispy-rule Rules)] > > * X -> X) > > > WARNING: > > DEFUN/DEFMACRO: redefining function macroexpand in C:\Documents and > > Settings\Use > > r\Desktop\Qi II\Qi 9.2\startup.txt, was defined in C:\Documents and > > Settings\Use > > r\Desktop\Qi II\Qi 9.2\Qi 9.2.txtmacroexpand > > > (3-) (define factorial > > * (-> (0) 1) > > * (-> (X) (* X (factorial (- X 1))))) > > factorial > > > (4-) (factorial 6) > > 720 > > > I think the moral here is - be careful of what you wish for. > > > Mark > > And with this new macroexpand, will all other Qi 'machinery' work as > previously? > Is there an 'idiomatic way' to program in Qi (I mean from your point > of view -- I understand, that anyone is free to do what he likes) and > does this prefix pattern matching variant align with the idiomatic > way? > > Thanks, > Vsevolod- Hide quoted text - > > - Show quoted text - Yes; very much so. The macroexpand function works on the Qi reader. So after the definition provided, you can load all your programs in prefix notation. I put these two functions in a file and loaded them. (define factorial (-> (0) 1) (-> (X) (* X (factorial (- X 1))))) (define rev (-> (()) ()) (-> ((cons X Y)) (append (reverse Y) (cons X ())))) If you wanted to accomodate signatures in the functions it would require a few more lines in macroexpand. You can program Qi to look like ML or Haskell if you wanted. But personally I don't like the total prefix notation much - its longer and more bracket cluttered than the native idiom. But Qi actually supports an M-level and an S-level syntax. [...] is just short for (cons ...) and is parsed as such. The advantage of the S-level syntax is that it gives Qi the same metaprogramming capability that Lisp has got (perhaps better in some ways). The advantage of the M-level is its brevity when writing programs. Historically Lisp was supposed to have both. So in a sense Qi has restored something that was part of the original intention, except that McCarthy's intended M- level was different from Qi. Mark |
|
#49
| |||
| |||
| > > > (3-) (define factorial > > > * (-> (0) 1) > > > * (-> (X) (* X (factorial (- X 1))))) > > > factorial Cool, you added extra parenthesis around the input parts, 0 and X. Why? I'm struggling to see why not just use (-> 0 1) This is all actually what I meant by the post at: http://groups.google.co.uk/group/Qil...3b04eb5e?fwc=1 Thanks for the macro code, maybe I'll look into using the language again. > > > I think the moral here is - be careful of what you wish for. In this case, if I did that I'd instead have to rip out my guts from the feeling their giving me. By formatting the data with prefix, you pave the way for a) Greater ability to re-use the code as data and in macro's. b) Possibility of writing your code more concisely as a result. The (-> 0 1) above might become (0 1) as similar to a let form. Dare I say it, but if ever an indentation syntax reader were introduced, I would use it, and I would type this: mydef factorial 0 1 X (* X (factorial (- X 1)) I would imagine you used the current Qi syntax (partly) to make the code easier for people to type. Personally, I find the above to be even easier, regardless of whether an arrow is necessary to focus the eyes. For those of you spinning with rage at my insolence, here's the above code without my hypothetical indent-reader: (mydef factorial (0 1) (X (* X (factorial (- X 1)))) Of course, if you like, those wrapping parens can be removed anyway in the same way that Qi does, but I would see that as a bad idea. Ali |
|
#50
| |||
| |||
| On 31 ago, 23:07, Ali <emailalicl...@gmail.com> wrote: > > > > (3-) (define factorial > > > > * (-> (0) 1) > > > > * (-> (X) (* X (factorial (- X 1))))) > > > > factorial > > Cool, you added extra parenthesis around the input parts, 0 and X. > Why? I'm struggling to see why not just use (-> 0 1) What if the defined functions takes more than 1 argument? The parenthesis mean a list of arguments, in this particular case, just one. Why do people living in Lisp keep mumbling about parenthesis? It gets away with ambiguities and is an excelent aid in simple structured editing. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.