Paste: Patch for lighter weight syntax in let

Author: dharmatech
Mode: factor
Date: Sat, 22 Nov 2008 13:51:12
Plain Text |
! Allows for assigning numbers and literal arrays
! to bindings:
!
! [let | A 10 | A ]
!
! [let | A { 1 2 3 } | A ]
!
! The above would normally be:
!
! [let | A [ 10 ] | A ]
!
! and
! 
! [let | A [ { 1 2 3 } ] | A ]

: parse-binding ( -- pair/f )
  scan
    {
      { [ dup "|" = ] [ drop f ] }
      { [ dup "!" = ] [ drop lexer get next-line parse-binding ] }
      {
        [ t ]
        [
          scan
          {
            { [ dup "["  = ] [ drop \ ] parse-until >quotation        ] }
            { [ dup "{"  = ] [ drop \ } parse-until >array 1quotation ] }
            { [ dup "[|" = ] [ drop parse-lambda ] }
            { [ dup string>number ] [ string>number 1quotation ]        }
          }
          cond
          2array
        ]
      }
    }
  cond ;

New Annotation

Summary:
Author:
Mode:
Body: