Arc Forumnew | comments | leaders | submitlogin
Why Arc is good for video games (arcfn.com)
14 points by kens 5797 days ago | 6 comments


6 points by almkglor 5797 days ago | link

Hmm. So another priority: a decent error system.

I've been wondering about decent error/exception handling recently. One particular bit I noticed in C++ is that throwing is something like this:

  class MyExceptionType : std::exception {
    /*blah blah...*/
  }
  void random_function(void){
    /*blah blah*/
    throw(MyExceptionType(my_specific_reason));
  }
To me this seems like an Arcish way to do it:

  (def random-function ()
    ; blah blah
    (err:annotate 'MyExceptionType my-specific-reason))
Any special exception-handling would look like this:

  (on-err
    (fn ()
      #|do stuff...|#)
    (fn (e)
      (if (isa e 'MyExceptionType)
          (let reason (rep e)
            #|handle according to reason|#)
          ; unknown error, rethrow:
          (err e))))
In fact, I have a draft implementation of 'on-err and 'err for arc2c:

  (set on-err
    (fn (f fh)
      (ccc
        (fn (k)
          ; let tmp (%curr-err)
          ((fn (tmp)
             ; set up a continuation guard
             (%cont-guard-up)
             (%set-err
               (fn (e)
                 ; tear down continuation guard
                 ; and current error handler
                 (%cont-guard-down)
                 (%set-err tmp)
                 ; so that if fh throws, it throws
                 ; on the original err instead of
                 ; recursing
                 (k (fh e)) ))
             (f)
             ; tear down continuation guard and
             ; reset error handler
             (%cont-guard-down)
             (%set-err tmp))
            (%curr-err))))))
  (set err
    (fn (e)
      ((%curr-err) e)))
  (%set-err
    (fn (e)
      (%pr "Error of type: ")
      (%prn (%type e))
      (%pr "Error: ")
      (%prn (%rep e))
      (%halt)))
%curr-err and %set-err would have to set a thread-local variable in the C-side. %cont-guard-up and %cont-guard-down just need to set up continuation guards.

-----

1 point by almkglor 5796 days ago | link

Done and on arc2c.git

Continuation guards are not yet implemented though.

Edit: For when macros finally (!!) get into arc2c:

  (mac catch-err (expr . body)
    (givens p (pairs body)
            e (uniq)
            to-isa
            (fn (el)
              (if (no:cdr el)
                  el
                  (let (type exp) el
                    `((isa ,e ,type) ,exp))))
            clauses (mappend to-isa p)
      `(on-err
         (fn () ,expr)
         (fn (,e)
           (if ,@clauses)))))

-----

1 point by tung 5797 days ago | link

It may not be pure OpenGL, but my OpenGL book says that glXUseXFont will load an X font, which builds a bunch of display lists, each one of which containing a character rendered with that font.

I'm curious though. Why OpenGL? SDL plus SDL_ttf could have handled things just as well, plus Y would have pointed down, not up.

-----

2 points by kens 5797 days ago | link

PLT Scheme's OpenGL interface doesn't support glx, so I couldn't use glXUseXFont.

What are SDL and SDL_ttf? Is there any way to use them from Arc?

-----

4 points by tung 5796 days ago | link

http://www.libsdl.org/

Simple DirectMedia Layer. Cross-platform multimedia library that has audio, input and 2D graphics. SDL_ttf is a standard extension to it that provides TrueType font support. If Arc can load C libraries, it can should be able to load SDL.

-----

1 point by stefano 5796 days ago | link

In anarki, you can use ffi.scm to import C functions.

-----