Another finished project! (yay!)

This was a fun little project that took just few days to finish. I recommend you try this at some point in a language you are not familiar with.

The last parts

So the one thing still left to do was make interactives able to broadcast to the server as well. To do this, I somehow needen to export broadcasting words to the config namespace. The simplest way I thought of was to define a function in config-space that when called, takes all the broadcast functions as arguments to define bind them to new symbols.

(Well, I'm calling them 'functions', but Scheme technically calls them 'procedures'. I'm not gonna argue about the correctness of that choice, but it just seems wrong to call them 'procedures' in LISP...)

(define (get-access brd-server brd-world brd-place
                    usr? usr-name set-usr-name!
                    usr-color set-usr-color!
                    usr-description set-usr-description!)

  (set! broadcast-server brd-server)
  (set! broadcast-world brd-world)
  (set! broadcast-place brd-place)

  (set! user? usr?)
  (set! user-name usr-name)
  (set! set-user-name! set-usr-name!)
  (set! set-user-color! set-usr-color!)
  (set! set-user-description! set-usr-description!))

I have also made all the broadcast functions able to take exception users. I have also written some wrapper functions for them when exporting.

(define (grant-access)
    (export-access
      (lambda (u txt #!key (exception #f))
        (broadcast-server txt #:exception (if exception u '())))

      (lambda (u txt #!key (exception #f))
        (broadcast-world txt (user-world u) #:exception (if exception u '())))

      (lambda (u txt #!key (exception #f))
        (broadcast-place txt (user-place u) #:exception (if exception u '())))


      user?
      user-name set-user-name!
      user-color set-user-color!
      user-description set-user-description!)))

All the lambdas in interactive interact text now take two arguments: the user interacting and any arguments they might pass after the interaction command.

(import srfi-1)

(define hall
  `((description "A long hallway leading to places")
    (places
      (main
        (welcome "You feel like you have been there before...")
        (interactives
          (poster
            "An old poster of some old band. It feels old..."
            "You looked at it. You feel old.")

          (thing
            "<args> A simple thing. It speaks sometimes"
            ,(lambda (args user)
               (if (not (null? args))
                 (broadcast-world user
                                  (fold (lambda (a b)
                                          (string-append b " " a))
                                        "THE THING SAYS:" args)))
               "")))

        (pathways
          (forwards
            "Further into the hallway"
            main))))))

One thing about Scheme I don't really like is that a lot of common list functions like 'filter', 'reduce' or 'fold' are locked in 'srfi-1'.

I know that they are not that hard to implement, but it would be nice to just include them. This is the thing about Scheme. Even the heavier 'R7RS' version is very minimal and most of the common stuff you would expect to be in some sort of standard library are defined through 'SRFI's.

This is fine, but I would appreciate if at least the common ones like 'srfi-1' would be included with CHICKEN instead of being an external package you have to install.

This is a minor complain, but I still feel like mentioning it, since I'm used to using as few external libraries as possible, which is clearly not the way Scheme is supposed to be used.

END

You can get the code here.

There is more I could have done, like making custom commands or, you know, a proper documentation. But as I don't plan on actually using it, nor do I expect anyone else doing so, I therefor proclaim it finished as is.