(hello

‘world)

SMOS

A quick hack, does what I needed it to do. Namely, manage access to ancestor’s methods a little more like YASOS. Maybe someone’ll find it useful.

Perma link for updates and such: http://prael.wordpress.com/smos/

smos.scm

;;;; smos.scm
;;;; Still Macroless Object System.
;;;; This code is still in the public domain.
;;;; No warrany. In fact, I guarantee that even looking at this code will break your shit, leaving you destitute and homeless.

;;;; 0.0.2
;;;; Broke out vector stuff, in case obj's structure changes later.
;;;; Somewhat YASOS-ify ancestor handling. Ancestors are now stored in a vector.
;;;; (make-method! self some-method (lambda (self) (operate-as self a-number-in-ancestors-vector some-other-method)))

;;;; 0.0.1
;;;; Initial copy of MOS.

;;;; Object Construction:
;;;;       0           1          2             3              4             5         6
;;;; #(object-tag get-method make-method! unmake-method! get-all-methods ancestors operate-as)

;;;; Original header: ----------------------------------------------------
;;; "object.scm" Macroless Object System
;;; Author: Wade Humeniuk <humeniuw@cadvision.com>
;;;
;;; This code is in the public domain.

;;;Date:  February 15, 1994

;; Object Construction:
;;       0           1          2             3              4
;; #(object-tag get-method make-method! unmake-method! get-all-methods)
;;;; ---------------------------------------------------------------------

(define object:tag 'object)

(define (obj:tag obj)
  (vector-ref obj 0))
(define (obj:get-methods obj)
  (vector-ref obj 1))
(define (obj:make-method! obj)
  (vector-ref obj 2))
(define (obj:unmake-method! obj)
  (vector-ref obj 3))
(define (obj:get-all-methods obj)
  (vector-ref obj 4))
(define (obj:ancestors obj)
  (vector-ref obj 5))
(define (obj:operate-as obj)
  (vector-ref obj 6))

(define (object? obj)
  (and (vector? obj)
       (eq? object:tag (obj:tag obj))))

;;; This might be better done using COMLIST:DELETE-IF.
(define (object:removeq obj alist)
  (if (null? alist)
      alist
      (if (eq? (caar alist) obj)
          (cdr alist)
          (cons (car alist) (object:removeq obj (cdr alist))))))

(define (operate-as obj ancestor-number method)
  (if (object? obj)
      ((obj:operate-as obj) ancestor-number method)
      (error "Cannot access ancestors of non-object: " obj)))

(define (get-all-methods obj)
  (if (object? obj)
      (obj:get-all-methods obj)
      (error "Cannot get methods on non-object: " obj)))

(define (make-method! obj generic-method method)
  (if (object? obj)
      (if (procedure? method)
          (begin
            ((obj:make-method! obj) generic-method method)
            method)
          (error "Method must be a procedure: " method))
      (error "Cannot make method on non-object: " obj)))

(define (get-method obj generic-method)
  (if (object? obj)
      ((obj:get-methods obj) generic-method)
      (error "Cannot get method on non-object: " obj)))

(define (unmake-method! obj generic-method)
  (if (object? obj)
      ((obj:unmake-method! obj) generic-method)
      (error "Cannot unmake method on non-object: " obj)))

(define (make-predicate! obj generic-predicate)
  (if (object? obj)
      ((obj:make-method! obj) generic-predicate (lambda (self) #t))
      (error "Cannot make predicate on non-object: " obj)))

(define (make-generic-method . exception-procedure)
  (define generic-method
    (lambda (obj . operands)
      (if (object? obj)
          (let ((object-method ((obj:get-methods obj) generic-method)))
            (if object-method
                (apply object-method (cons obj operands))
                (error "Method not supported: " obj)))
          (apply exception-procedure (cons obj operands)))))

  (if (not (null? exception-procedure))
      (if (procedure? (car exception-procedure))
          (set! exception-procedure (car exception-procedure))
          (error "Exception Handler Not Procedure:"))
      (set! exception-procedure
            (lambda (obj . params)
              (error "Operation not supported: " obj))))
  generic-method)

(define (make-generic-predicate)
  (define generic-predicate
    (lambda (obj)
      (if (object? obj)
          (if ((obj:get-methods obj) generic-predicate)
              #t
              #f)
          #f)))
  generic-predicate)

(define (make-object . ancestor-list)
  (define method-list (list))
  (define ancestors (list->vector (cons 'i-wish-self-could-go-here-but-i-dont-have-macros ancestor-list)))
  (define num-ancestors (length ancestor-list)) ; I can't seem to (vector-length ancestors) here.
  (define (operate-as obj-num method)
    (method (vector-ref ancestors obj-num)))
  (define (make-method! generic-method method)
    (set! method-list (cons (cons generic-method method) method-list))
    method)
  (define (unmake-method! generic-method)
    (set! method-list (object:removeq generic-method method-list))
    #t)
  (define (methods) method-list)
  (define (get-method generic-method)
    (let ((method-def (assq generic-method method-list)))
      (if method-def
          (cdr method-def)
          (let loop ((current-ancestor 1))
            (if (> current-ancestor num-ancestors)
                #f
                (let ((method-def ((obj:get-methods (vector-ref ancestors current-ancestor)) generic-method)))
                  (if method-def
                      method-def
                      (loop (+ 1 current-ancestor)))))))))
  (vector object:tag get-method make-method! unmake-method! methods ancestors operate-as))

;; Samples:

;; SMOS/MOS:
;;
;; > (define name (make-generic-method))
;; > (define job (make-generic-method))
;; > (define (person n)
;;     (define self (make-object))
;;     (make-method! self name (lambda (self) n))
;;     self)
;; > (map name (list (person 'bob) (person 'ashley) (person 'george)))
;; (bob ashley george)
;; > (define (worker n j)
;;     (define self (make-object (person n)))
;;     (make-method! self job (lambda (self) j))
;;     self)
;; > (map name (list (worker 'bob 'mechanic) (worker 'ashley 'pilot) (worker 'george 'loanshark)))
;; (bob ashley george)
;; > (map job (list (worker 'bob 'mechanic) (worker 'ashley 'pilot) (worker 'george 'loanshark)))
;; (mechanic pilot loanshark)
;; >

;; SMOS operate-as:
;;
;; > (define name (make-generic-method))
;; > (define is (make-generic-method))
;; > (define job (make-generic-method))
;; > (define really (make-generic-method))
;; >  (define (person n)
;;     (define self (make-object))
;;     (make-method! self name (lambda (self) n))
;;     (make-method! self is (lambda (self) 'person))
;;     self)
;; >  (define (employee n j)
;;     (define self (make-object (person n)))
;;     (make-method! self job (lambda (self) j))
;;     (make-method! self is (lambda (self) 'slave))
;;     (make-method! self really (lambda (self) (operate-as self 1 is)))
;;     self)
;; > (name (employee 'bob 'mechanic))
;; bob
;; > (is (employee 'bob 'mechanic))
;; slave
;; > (really (employee 'bob 'mechanic))
;; person

(define name (make-generic-method))
(define is (make-generic-method))
(define job (make-generic-method))
(define really (make-generic-method))
(define (person n)
  (define self (make-object))
  (make-method! self name (lambda (self) n))
  (make-method! self is (lambda (self) 'person))
  self)
(define (employee n j)
  (define self (make-object (person n)))
  (make-method! self job (lambda (self) j))
  (make-method! self is (lambda (self) 'slave))
  (make-method! self really (lambda (self) (operate-as self 1 is)))
  self)
(name (employee 'bob 'mechanic))
(is (employee 'bob 'mechanic))
(really (employee 'bob 'mechanic))

July 6, 2009 Posted by prael | Programming, Scheme | | No Comments Yet

ParrotVM

Makes my pants uncomfortable. Register based, tail call optimizing, supports call/cc(!), has the beginnings of JIT compilation… the GC isn’t exactly bleeding edge but at least isn’t one of the stop-the-world sorts (something about 3 color marks and a background thread doing incremental sweeping IIRC), and like the layout algorithms in xmonad it is easy to replace with something better when one comes around. Oh yeah, and threading. Decent looking FFI. The promise of calling libs from other languages in the future (like the way OCaml can talk to any Perl module from CPAN). And it reached 1.0 with a stable API recently. And interestingly there seems to be talks about working along side the LLVM folk…

There’s just a lot of cool shit going on here. Whereas Java/.Net are trying to bolt in the infrastructure to support dynamic languages, Parrot’s designed from the ground up to do this.

Perhaps GC wouldn’t matter much if something like newLISP with its funky one reference only “GC” were ported to it… on that note I should try to compile newLISP to LLVM bytecode.

And Java’s planning (apparently) on supporting TCO and if it already did, so would Clojure (the recur thing just drives me loopy, pun intended), and I probably never would have noticed Parrot.

For that matter, Clojure on Parrot would rock my balls too. And there’s word of Parrot eventually maybe understanding JVM/.Net bytecode… shouldn’t be much of a tweak from there…

You know? A few months ago I found myself wishing I had been born in the 60’s or 70’s, so I could have been around when all of the cool Lisp stuff was happening. I think I’ve changed my mind… this is a fucking awesome time to be here.

And as long as my ParrotVM post has turned into an obscure Lisp post, I should mention Arc. Arc is a Lisp. There, I mentioned it. Now let’s never speak of that again.

April 3, 2009 Posted by prael | Programming, Scheme | | No Comments Yet

Who wants a non-toy R5RS Scheme on the Parrot VM?

So do I, go write me one. Here’s how (I hope):

pre-scheme is essentially a lispy-syntax C, complete with memory allocations, freeing, goto, minimal TCO, no GC… basically disgusting from a (this, anyway) lisper’s POV, and a far cry from the shear sexiness of R5.

The interesting thing about it though (other than making C a saner language) is that Scheme48’s VM is implemented via Scheme48’s pre-scheme->C translator, which as it happens, in true Lisp fashion, is itself implemented in Scheme. And I’d imagine implementing the minimalistic pre-scheme to be a far sight easier than implementing all of R5. You can look at the Scheme48 distribution’s makefile to see how to go about getting pre-scheme loaded to play with.

It may be a weird way to go about it, running a stack based VM atop a register based one (let alone one wanting malloc/free), but I’d think it to be the quickest route towards non-toy R5 on Parrot, and if nothing else a sufficient stop-gap until “native” implementations approach practical usability. Plus you already have most of your test suite for free.

Of course I havn’t looked into this in any depth, particularly what the Parrot implementation of pre-scheme would need to do other than parse the syntax. And I don’t really have the time to. So I thought I’d toss the idea out there and see if anyone else picks it up. What the hell, it’s worth a shot right?

April 3, 2009 Posted by prael | Programming, Scheme | | No Comments Yet

I’m still alive.

Has been busy around here lately.

March 17, 2009 Posted by prael | Uncategorized | | No Comments Yet

SoLoad: Enough FFI to get the job done.

Process based pseudo FFI. Fucking awesome. I had been doing similar stuff with tclsh and wish via snow’s tk package to take advantage of TCL libraries, but this looks to be much much nicer and provides access to C libs.
If you don’t need callbacks or worry much about continuations, this should save a great deal of headache. And if you do, well, a few scheme implementations support SWIG anyway.

SoLoad intro
SoLoad basic
SoLoad intermediate
SoLoad at Launchpad
SoLoad wiki

December 18, 2008 Posted by prael | Uncategorized | | 1 Comment

1986 Mac Plus keeps up pace with 2007 AMD Dual-Core.

86 Mac Plus Vs. 07 AMD DualCore. You Won’t Believe Who Wins — because it’s not the size of the processor, but what you do with it.

November 13, 2008 Posted by prael | web | | No Comments Yet

PayPal just fucked me.

Been busy the last couple months, working on houses, getting some cash together. Finally did, and got a few books regarding web design. Just made a simple site, it came out quite nicely. Got a PalPal account so they could pay, and they did. Went to add my bank acct and verify it… whoops, “You are currently not allowed to add a bank account because your account access has been limited.”. Everything in PayPal’s help area regarding such, with the steps for fixing it, don’t work. There’s nothing in the “Resolution Center” most of them reference. I just confirmed my cell phone, upgraded it to Premier, and still the same deal.

What. The. Fuck?

Yes, I’ve tried to call them. It’s a bunch of voice prompts, all the options being things already on their site.

Yes, I’ve tried to email them, it says 2-4 days for a reply which will probably be canned anyway.

Update: The resolution seems to have been to upgrade to a business acct. Can’t imagine why… bank acct in my name, I wasn’t planning on switching to a business PayPal acct until I got one as such from my bank. Go figure. Waiting for the deposits to verify the bank acct now. Any more problems and I’m going to just drop PayPal and get a merchant account.

Update: Woke up, checked to see if the two little deposits paypal makes to verify account had been made, and they hadn’t been. Nothing unusual, it can take 3-4 days and I started it on a weekend anyway. Checked paypal acct, and I see this:

We recently reviewed your account, and we need more information about your business to allow us to provide uninterrupted service. Until we can collect this information, your access to sensitive account features will be limited. We would like to restore your access as soon as possible. We apologize for the inconvenience.

Why is my account access limited?

Your account access has been limited for the following reason(s):
Sep. 22, 2008: We have detected suspicious activity regarding the receipt or withdrawal of funds.

Apparently, there were two refunds. Except my one customer swears they didn’t request one, and the 2nd one is… a whole 10 dollars, which was from my self when I set up the acct to make sure I could accept $ with it. I fucking know I didn’t request a refund from my self. Again: What. The. Fuck?

Needless to say, I’m not fucking amused at all. I will attempt to get my fucking money out of this situation, but considering their well known history of this crazy shit, I’m not expecting much. Damned thing is I knew about this going in. It was just the only real way I could accept a payment at the moment. I was so happy, too. Was going to use the cash to get a business license, open a new bank acct for it, get a proper domain and hosting, and buy more books to study, particularly regarding PHP5, as most of my PHP knowledge is from when PHP4 was new. Now I have nothing.

I’ll just have to borrow the cash I need, and work my way from there. Which is precisely what I was trying to avoid having to do. Needless to say, no more of my earnings will be trusted to PayPal.

September 20, 2008 Posted by prael | Annoyances, Life, Malware, web | | 2 Comments

Just a little food for thought…

Ever had a “gut feeling”?

Maybe it was your Enteric Nervous System

More here, here, and here.

Just a little food for thought. ;)

July 24, 2008 Posted by prael | Life | | No Comments Yet

On a related note, wrt privacy.

July 19, 2008 Posted by prael | Life | | No Comments Yet

No more Facebook.

Logged In or Out, Facebook Is Watching You

Facebook A Black Hole For Personal Info

Facebook Sharing Too Much Personal Data With Application Developers

Facebook Widget Installs Zango Spyware

Facebook Caves To Privacy Protests Over Beacon

Facebook Beacon Privacy Issues Worse Than Previously Thought?

Facebook Retreats on Online Tracking

Facebook Users Complain of New Ad-Based Tracking

The New Facebook Ads – Another Privacy Debacle?

From Facebook’s Terms of Service:

When you post User Content to the Site, you authorize and direct us to make such copies thereof as we deem necessary in order to facilitate the posting and storage of the User Content on the Site. By posting User Content to any part of the Site, you automatically grant, and you represent and warrant that you have the right to grant, to the Company an irrevocable, perpetual, non-exclusive, transferable, fully paid, worldwide license (with the right to sublicense) to use, copy, publicly perform, publicly display, reformat, translate, excerpt (in whole or in part) and distribute such User Content for any purpose, commercial, advertising, or otherwise, on or in connection with the Site or the promotion thereof, to prepare derivative works of, or incorporate into other works, such User Content, and to grant and authorize sublicenses of the foregoing. You may remove your User Content from the Site at any time. If you choose to remove your User Content, the license granted above will automatically expire, however you acknowledge that the Company may retain archived copies of your User Content. Facebook does not assert any ownership over your User Content; rather, as between us and you, subject to the rights granted to us in these Terms, you retain full ownership of all of your User Content and any intellectual property rights or other proprietary rights associated with your User Content.

July 19, 2008 Posted by prael | Annoyances, Life, Malware, web | | No Comments Yet