s c h e m a t i c s : c o o k b o o k

/ Cookbook.NondeterministicCFG

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Non-deterministic Context Free Grammars

Problem

The amb procedure works wonders. It does -seem- to have a serious issue, if formed as offered in "Teach Yourself Scheme in Fixnum Days" and other places.

That problem is arbitraririly (lazy) recursively defining amb functions. It just seems to refuse to work...Either from the recursion, or from the promises, which brings us to Context Free Grammars.

It's very easy to define a CFG's branches as an AMB of promises

Here's an example of what I mean. ("force-tree" just runs through every branch of a list and forces any promises it finds, until no promises exist in that tree)

;Define a 
> (define (cfgA) (amb (list "") (list "a" (delay (cfgA)) "b") ))
> (define foo (cfgA))
("")
> foo
("")
> (amb)
("a" ("") "b")
> foo
("a" ("") "b")
> (amb) ;;Weird output here..it doesn't change one bit!
("a" ("") "b")
> foo
("a" ("") "b")
> (amb) ;;Strange here, too!  Why exhaust the tree when we have options?
. Amb tree exhausted

It seems to me amb doesn't work well with promises... If that were to resolve, a million new things would be work-trivial (while probably not overly efficient) in Scheme.

Solution

Discussion


Comments about this recipe

Contributors

-- CJayMartin - 10 Nov 2006

CookbookForm
TopicType: Recipe
ParentTopic:
TopicOrder: 999

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest