Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Scheme++

Name: Anonymous 2012-06-16 15:57

I'm implementing Scheme dialect with OOP, default argument values and some other features. How readable is it for you?

(define (fib n (memo . #{ (0 . 1) (1 . 1) }))
  (let ((memoized (: memo get n)))
    (if memoized (cdr memoized)
        (let ((result (+ (fib (- n 1)) (fib (- n 2)))))
          (: memo set! (n . result))
          result))))

Name: Anonymous 2012-06-16 16:25

>>1
Already that it's Lisp doesn't help.

(: memo set! (n . result))
I'm puking.

Name: Anonymous 2012-06-16 16:49

>>1

check out clos.


(get memo n)
(set memo n result)


using set to not confuse with set!.

Name: Anonymous 2012-06-16 17:38

>>1
Scheme will never see use in industry as long as CL and Clojure exist.

Name: Anonymous 2012-06-16 17:44

OOP is garbage anyway. OOP is Computational Marxism.

Name: >>3 2012-06-16 18:58

and an alternative interface:


(memo 'get n)
(memo 'set n result)

Name: Anonymous 2012-06-16 20:54

衘㤈䁔☠憀礇遀↓甶顐榖䐰梀㥂䡁桤茁艉灰䘸㚕ޕ鄑㙤協杉鉨蝄ゐᘦ偆䤴愕恳ࠢ銇ᕀ阳鄈⡃⎐‥ᙰᄵ炑ነ奸ሳ焑兘䄴荡ѐ卒̱ᝇ㥁䖇⁕卷☸桙ᕴ嘲㡅挣瘙✰䜙癤園靦鐴来鍠坨璉梆⦄ፀ祇㌁嘓锁㥵顩ᔇ獓喂鞄鈐㍴虡戁摒鐠♖圷撙膉㉔ቂ咃ѩ吗煠ᙱԖ饃㑑傂̅ň聘ᕲ萁㥰䐅硁愆㠧焐悗䘐噷逘←㡵ܵ奩䔲咀睸ކဘХ▄恠㜠ₔԉ‰隒ᙠ坳™䜹倒傖䙇阵䎕蝥ֆ㘸᐀ᎇŇ酂Ɉᔲ劀̸㐃蔡⅁啙靁ᔑЀ鄅ᤂᒈكत閂蠤餗璑٣栕ɷ፥鄣酔栅ၰ㔳餹r䤆砱㘗⚅Ґፐና牢դ覐㚀艥ᘧ鍷酶ᑢΕ煗3ƒ蚅兓晤⒖偖䦀倒癅䄠Ж牴頸㠢愠䄂鄔╆ቘ㤰礦葙ᑈ硶鐸琨㘁猳攅ᄁ荧fᘗ聆䁹爳ᜉ陂ȹ㐥⤶墙蕉要—鐓㥐䐲遄錖で㈦ខℱ⍩险㜹ሓ㌣ݸԕ؇䌢ŕ栱荷䠓愱䔑䡷锇䈒㢘㤲Ͳ恔倧ԥ䆀⡖顐⦀刄ᅗ蝩Ȉ饲鄇䤀╙

Name: Anonymous 2012-06-16 21:23

㑴ᝤ芈ᐰ 咘䅴蘡䀄ℰ椠ㆁ䎁塕䡑Ո瑢鑗ɸ☢Ƒ匩摶✶䤡ᝑĴ螇ᢂѡ䕅̷硙ܳ搡镕蕗戱葄Ғঈ煠舳攰慵膃鐇偲䠉针✧䄔ㅳܨ獥ᠲ呇Ň㊑鄄蔃戰搕煄㔃䡤獗萈襗摈ፕᐗ萄鉉畹劙銑挣堳᝕У恲椨∇ᅨ脆嘴㝉塡悘〗猅и閄㠠锘ᆗ耆爳Ғ㙴❃畵ႆ陶⡡剥䍲㥩厔⥦搐楸舄研ㅰ摅褘刉ő瀩W煲坉敶ᜄॅf撄愱җ⦇匤‖ጶ怦㡡ᅦ脑㥃ኄ適蝩䑲蘔煐ፀ鄇憔啢逑猅栁┗坱㑔栐उ楨扔җ獖㈡鈢舘ሓ蒂ゕ᠃夒酡憇❰㑅畲脶萁ᒙ∧䠇♠ᡓ顉祁⢇ថ⌉⦅瘨䥨ㅡ晠礆ሙ鉷Ж吱ᝃ芀塙脴搉ᙐ̢掐陶鈨㄀㔙㘂̀ㅸ奔塈䥘䤥撓㈩䜕鎃陹ၣΙ戳ᤔв頙䒅儹΁⠖焃ₒ猴䂈甔‴䄥朣ᅵ噸奖☁ⅇᠲ䕉ᙢ恅甴执恂⒅阈鍘礥塙儐䂀木い根荣奐䐴䙴ࡩᑸ⍒锤脸褐録䅗㔤x┐嘲☱㉩ₗᦀㄗᔅ萄㉓咗䚂‸喇瑑印ࡖw䎒㈥薘蕵䤱虅

Name: Anonymous 2012-06-16 21:45

阥焆熀扸隒呡鉹䈉砀妓鄹鑰थᡰ梓㉅Ւ䙳ᅡ鈹産搇蕴⦕愆餄邈䔇䅱☈熔䘐啸夐顄恵唅褴蜷醒㉨հ奄䡔㈸捀ၹշ㠰㍒☄㚅場眔榓〸呤在皙慵ȥ奆䖂W蔩掑陗蠶ᖑ琕蒂ႇ馐椸酑ቷ䡅ቶ圖吤ᝈ畠瀩退杴挵瀔挨䄸晙㤀畅A折䘦餄荧鐸蕉木瘴蒘ॷ鞘陙ᥦ脱㤈脶┇匕獙ဂ摸⚉Щ褅蠂䐀熃∲撕蚉䠤⑧呗琧㝡☸㍦᝹ঘ➉兢怒ሧ蒃衳ኇ圡錁㝳䜅䠨ᖐ㍲こᕧ眱袄聐椂ጇ阁皖㤧敳挀ᠵŰ刖覒餘㤘㐨馒猃蜧݆䑒ᅕ䡦䡴␀碖∇嚅硢錷♴̄桤鞑錰震膘脉匂⤳馈≒蔵醃怄猩恡怇霰ᠧ鐶鎉芖㔥虸饷䍔憗蠴焲梔碃蕠鐖⍵Ր茈०┦℣蘔ႀ΂酘鑠䐁⡨锆頦枆ᘣ⊕捆钖妄蘣(け掑焸ⅉ䕹㚈塉蜃袘▓␇₇቙⡡㌔Α匑襢嘦Ʌ吙 ⑤坓䎑ᒅᕨ䔑䄓刈⅃䎒咒礹獤䀰虨㌠愘眱㠡啔♕啁蘙獦ᑠ鄕̩褤镵萓蒆蜉❣䒐ᄕ眔噃鑸杕`鑔

Name: Anonymous 2012-06-16 22:48

梉衩地閖⦔♶ጙ撒ᚔ襵▖䤰䡹璓㢖著恀鞔祡उ⌄㔒蜂獐㝘䑉ř頳椸♹眑鄙夦Ȅ䍱覓ሰ嚉焥栆蘀㦇䥦ᚄ噧睷禅戤攗偃挦鑲⤵䉈ȸ慐恷㈧蕙㈐㡀斉ᅂ晹ገ暐襓女ⅈ恃㜖䑆冄鞔↉䖀斘鄐的砐艕䔈瘂ঈ儥䅵陘⊒䠥眦‰敵Ȩٰ艥莃ᑂሦԒ需怷楠㍸共晲假ᅧ攔ࠇ䘵さ䙢㢅ጉؗ玉፧቙ᐢ㎘灨震㢗蔗蒄吨遷鍰蚇զ晰❘劈ᘀ楄睶慷š蜠儐✑〥蚒妑ࠢ֔ؑ逗晗䠖ɲᄹ聲傁∡桅补䐑儃Ⅸ堵獵奰奈艖剗榀⑰荧࢖鄒♧愐奘䁱㘆䝳䅉⍠䘑北㤙┗眤䥦㥁襷瑠㥲危酑㕉舰rᙠलㅇ鎆⑨㥶茅虨㐶⠠☃虧镩晔ݶ表ᔡ⢐♹ᙀ႘遳鉲唨喉攔瘕脈茰䖈挀⊈隘␥虇顉碃㚔餷木戅┡晰%ȕ嚉耤撑慓⤰ᚁ⍑ᎁ⁧⍐䆔䦃搙慨ᎆ饃頉ȁ㦖蝉圷閇莁捆♅蝗′ঃ䀥醓焸砐膑蕐昘蝩瑅ڕण䍹砃椄猓膓霐䔤␸ᖁ၁〸噳٨䘱ձ桑ᒙ舨畢㝁ᕔ㎅

Name: Anonymous 2012-06-16 23:09

䦔腦鑃変䅲Աᙥ⤰搁ᆑ愅萁偡│㑈蜂禇煨禘蕓鐣杅茐饒顩㘕蕄ᖂ阑营腘鍅㖀脉ř䞘顐坉校鉁鑇⑉蘨啗预杘ड䡅䄐⢕‥暘遆际猗⍔玒㒁P㝘䔨∖‣㎑坶顉霈遉Έ琀ㄐ✕∢刳禐Щ偀̔ђ᜖祴碑䀆耆⁓莘䤐䝱㥄攦扉䎒鉤阡垇䒙頨㝗阗蘸塷锒⊁᝘馉ᘨ傂㌓ᐤ酦ħؓ⑆㄁砵䥙蚄ᔠ䙇靄᥆鎕昩硦畤䅳倳ᅳ∔Ť戙颁㙨噩昕䀹剘傘疔摒恥攆煐阃阳গ‐偒䝔會‱蚄霂☐䈄酆扙ѷ荃䑑来㐗Ֆ䕙颃㘦⌉楳昃㜐晖葤ᤰ⡕℀᜷鑇荡酀ℴԁ唹ݰ耒ᠣ瑇㢅醇ࠩ♹䆓ጓ喔⒄䆙㝈蜙预ᡓጠ礕皈草蜄楩襧暆㐕坰舡睘ɹ肕閑ᐶ㑹榅蜰蘧႓֖餷剘ّ茗⑶㙷遵挃䐉ጔ椄㜴熉照阑䌄䝵䅀甴椸⑓ɑॱ捴㍸衃斄皗嘳₀ɣ䄲䠩妈饩ऱ䤧呵㘡ㅣ硈ጸղ酴ጨፀݳчٗ᠄鍧ؙᔲ䤇蠀䑅┙ᘃ慇䤦攁ሒ銔䘲䀷鑣咓攉ₓ䅧€⡱⁄炒怹餴傂塓ᡀ

Name: Anonymous 2012-06-16 23:52

>>3
I've already thought about that way, but I want to be able to distinguish between function call and object's method call.
>>4
>Pure Scheme will never see use in industry
ftfy
>>6
I have also tried this, but it looks ugly and I want to make object itself callable.

Name: Anonymous 2012-06-17 4:56

I'VE ALREADY THOUGHT ABOUT THAT WAY, BUT I WANT TO BE ABLE TO DISTINGUISH BETWEEN FUNCTION CALL AND MY ANUS

Name: Anonymous 2012-06-17 5:47

>>12
but I want to be able to distinguish between function call and object's method call.

why?


[1]> (defclass A () ())
#<STANDARD-CLASS A>
[2]>
(defclass B () ())
#<STANDARD-CLASS B>
[3]>
(defclass C () ())
#<STANDARD-CLASS C>
[4]>
(defmethod poly ((a A))
  1)
#<STANDARD-METHOD (#<STANDARD-CLASS A>)>
[5]>
(defmethod poly ((b B))
  2)
#<STANDARD-METHOD (#<STANDARD-CLASS B>)>
[6]>
(defmethod poly ((c C))
  3)
#<STANDARD-METHOD (#<STANDARD-CLASS C>)>
[7]>
(map 'list #'poly (map 'list #'make-instance '(A B C)))
(1 2 3)

Name: Anonymous 2012-06-17 6:04

>>14
>why?
Because I think that code should be consistent and predictable. If you see something like this:

(define Foo
  (class ()
    (slots (cons (self arg) (display arg) (newline)))))
(cons (new Foo) 1)

what do you expect to get?
I expect to get a pair:
(#<object> . 1)
If using cons will print something ang return #<undefined> intead of usual pair, I will be very surprised.

Name: Anonymous 2012-06-17 6:43

>>15
The more powerful a feature the easier it is to shoot yourself in the foot with it.

Name: Anonymous 2012-06-17 6:54

>>15

That's true, there is the name clashing issue. A function name should either represent a function with a single implementation, or a virtual function with various implementations. It doesn't make any sense if you try to have both for the same function name.

Although you could say that the Foo implementation of cons is more specific than the generic cons, and that it overrides it. But in order for that to work, you have to treat all functions as methods. I can't think of an easy way to give that to scheme without making a new dialect.

Name: Anonymous 2012-06-17 7:10

>>16
Yes, but design should prevent it whenever possible.
>>17
>But in order for that to work, you have to treat all functions as methods. I can't think of an easy way to give that to scheme without making a new dialect.
It is easy to implement function call so it would look for object's method first, but it anyway violates the principle of least astonishment.
I'm still interested in /prog/'s opinion about my suggested syntax of module/object usage, ie:

(: modules ... function args ...)
;and
(: class/object method args ...)

Name: Anonymous 2012-06-17 13:58

so how'd you guys feel about a scheme with a static type system?

Name: Anonymous 2012-06-17 14:40

BAMPV AVTISMAE

Name: Anonymous 2012-06-17 16:54

>>19
No. Just no.

Name: Anonymous 2012-06-17 17:01

>>21
why? wouldn't it only make sense to extend scheme by a type-system, given most of them are introduced via extensions of pure lambda calculus?

Name: Anonymous 2012-06-18 1:25

>>19
SRFI-9

Name: Anonymous 2012-06-18 11:41

>>23
u wot m8

Name: Anonymous 2012-06-19 11:38

I revised my dialect and decided to add new datatype: selectors. They are similar to Erlang's atoms, meaning that they evaluate to themselves and they can't store any value. Selectors can be used in function call:
(define (foo bar baz) ...)
(foo baz: baz-value bar: bar-value)

in macros:
(define-syntax my-if
  ((my-if expr1 then: expr2 else: expr3)
    (if expr1 expr2 expr3)))

or everywhere else where you would usually use quoted symbol.
OOP was also revised. Now to call object's or class' method you just write:
(object method args ...)
without any annoying colon. Initially I wanted to use the same form, but with quoted method. Now I can see that the first argument(method name) just shouldn't be evaluated.

Name: Anonymous 2012-06-19 12:05

㙣ᠢᄈ霧䑔℅圣摒敀昧㡴Ĺ栵䀂䍇捉݄略挷㙆楒灅瘄䞒睶耵㕲㢄Ѷ吷晩鄘塁蒇瀢⎓瑵⁄҇ሡጴᎂ奆変㚐鍆膉㐷㈔肃̱ᐕ聉怸戄虰錄錈匸杠ゑ鄨坤夆礓阈億䥖䢃碀恰肔唶砅ᠩ阙ؒ猰☷癒┤醂⑧剒璔☃䒁偔蜠硐蔡儆镠敒㤑⠵蜰礒炐摀䀈䑂猩靡㑩㤑睹䝸噁ॕ❰撑扣坴榗᥆顄蜘⥆萅芒襵塆蝧㊘蚙┕ⅆ虈焙✣̡䈐杩֑坖鍩腳㕓㠱瑦睓艳႓偖⑉ॉ构牰䘥㜃靷敀衤㍄襃ॗ锉㤱䐔䥴ᚇ霄㐃㕸ᡀ鈃獴虉䜤锸䅁祑摃╉䝲䤴ᄸ剉䜈恗⑵攳⚕蜐垔栲戥᥅煰᜶耘ᘉ鉸朁䐆桂ဉ֘捄甦㘹噲㡡鎕鈆蝷ࠆᅸ㍰瘲≐栲㢔椹蔦㔒牣晡隘䍩芀⠙鍤⎃ᔙ蒃㖕ᥖ㢘聳呄㐱栨兄ࡃ瘆靧䔄镀耶腐向рᦉ鄆╙㖐舄偄镉Ͳ䙗捄焱╠董も᎖䑱㐶阤Ա祹㖃虣ᄓ奦艶⤧閁〉鍂䁵ゖ䥢➒琑馆茙劅琩褹饈 ᅩ硔腲Ȗ⚗頲呑恶愣⒅㠐关㞈ቸࡷ

Name: Anonymous 2012-06-19 23:00

>>25

If you used (object 'method-name-literal args ...) instead, then you could have a variable represent a method name, and there would be more purity and flexibility in the object. IE, it can be considered as just another closure. Consider calling the following on a vector of objects of the same type:


(define (vectorize-fns fns-vector)
  (lambda args
    (vector-map (lambda (fn) (apply fn args))
                fns-vector)))


So now say you have a vector of objects that implements some interface, IExample, and then you apply vectorize-fns to this vector and store the result in B. B will be an object that implements each method in IExample, but the return value of each method with be vectored.

Name: Anonymous 2012-06-20 0:40

>>27
Damn, I completely forgot about functional part while thinking about OOP implementation. Yes, it is better to evaluate method name for more flexibility and consistency at the same time.
But the quote in this place still annoys me. May it be better to replace quoted symbol with self-evaluating atom?

Name: Anonymous 2012-06-20 2:15

>>28
impossible even using macros since you don't know whether something will be an object. you could define! all those symbols to be equal to their own name, but that's going to bite you in the ass quick enough. just do multimethods, dude, and only store fields in objects.

Name: Anonymous 2012-06-20 4:14

>>28
yeah, for reasons >>29-san described, you can't do it. You could if you went back to the (: object method-name ...) syntax and made : a macro, but that was fugly as fuck.

Name: Anonymous 2012-06-20 4:30

>>29
>>30
I don't get it. What exactly impossible?

Name: Anonymous 2012-06-20 4:36

>>31

to get:


(X Y Z W)


to actually be:


(X 'Y Z W)


based upon what X happens to be, at runtime.

Name: Anonymous 2012-06-20 4:53

>>32
Meh. It will be possible if I make it possible in my interpreter.
But what I meant by "self-evaluating atom" was not quoted symbol, but _atom_ which I described here: >>25
I mean I am going to make method call look like either:
(window 'add-button button)
where method is accessed via symbol, or
(window add-button: button)
where method is accessed via selector(atom).
I understand that the difference is barely notable, but I hope you know how even tiniest design flaw can make programming awful.

Don't change these.
Name: Email:
Entire Thread Thread List