From 67e9dc92e0ac6503c3ce239444ee5822c0087e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 18 Nov 2015 15:28:23 +0100 Subject: [PATCH] [make works] Started writing about the queues in graph2.lp2.rkt, and started writing the code using the module --- graph/graph/graph2.lp2.rkt | 118 +++++++++++++++++++++++++++++-------- 1 file changed, 95 insertions(+), 23 deletions(-) diff --git a/graph/graph/graph2.lp2.rkt b/graph/graph/graph2.lp2.rkt index 818bc65..89c802e 100644 --- a/graph/graph/graph2.lp2.rkt +++ b/graph/graph/graph2.lp2.rkt @@ -1,4 +1,4 @@ -#lang scribble/lp2 +#lang debug scribble/lp2 @(require "../lib/doc.rkt") @doc-lib-setup @@ -159,7 +159,7 @@ In particular, it does not handle recursive types described with @tc[Rec] yet. In this section, we will describe how the @tc[make-graph-constructor] macro is implemented. -@subsection{The different types of a node} +@subsection{The different types of a node and mapping} A single node name can refer to several types: @@ -174,6 +174,9 @@ A single node name can refer to several types: must be replaced by promises for these. For example, @racket[[City (Listof (Promise Street)) (Listof (Promise Person))]].}] +When the user code calls a mapping, a placeholder is instead returned. We +therefore will have one placeholder type per mapping. + @subsection{The macro's syntax} We use a simple syntax for @tc[make-graph-constructor], and make it more @@ -182,7 +185,7 @@ flexible through wrapper macros. @chunk[ (make-graph-constructor [node type ...] - root:expr + (root-expr:expr ...) [(mapping [param (~literal :) param-type] ...) (~literal :) result-type body] ...)] @@ -195,27 +198,94 @@ and replace these parts with promises. The latter, @tc[fold-queue], will be used to process all the pending placeholders, with the possibility to enqueue new ones as these placeholders are discovered inside incomplete nodes. -@chunk[ - (define-syntax/parse - #'( - (set 10 11 12) - (void) - (λ (e acc) (values (format "{~a}" e) acc)) - (λ (e acc x get-tag) - (let*-values ([(t1 acc1 x1) (get-tag (if (even? e) - (floor (/ e 2)) - (+ (* 3 e) 1)) - acc - x)] - [(t2 acc2 x2) (get-tag 127 acc1 x1)]) - (values (list 'a e t1) acc2 x2)))))] +When the graph constructor is called with the arguments for the root parameters, +it is equivalent to make and then resolve an initial placeholder. We will use a +function from the @tc[fold-queue] library to process the queues of pending +placeholders, starting with a queue containing only that root placeholder. +We will have one queue for each placeholder type@note{Otherwise, when extracting + an element from the collection of results, we would need a @racket[cast].}. The +queues' element types will therefore be these placeholder types. + +@chunk[ + ] + +The return type for each queue will be the corresponding with-promises type. + +@chunk[ + ] + +@; Problem: how do we ensure we return the right type for the root? +@; How do we avoid casts when doing look-ups? +@; We need several queues, handled in parallel, with distinct element types. +@; * Several result aggregators, one for each type, so we don't have to cast +@; * Several queues, so that we can make sure the root node is of the expected +@; type. + +@; TODO: clarity. +@(void #| +The @tc[fold-queues] function allows us to associate each element with a tag, so +that, inside the processing function and outside, we can refer to an element +using this tag, which can be more lightweight than keeping a copy of the +element. + +We will tag our elements with an @tc[Index], which prevents memory leakage: if +we kept references to the original data added to the queue, a graph's +representation would hold references to its input, which is not the case when +using simple integers to refer to other nodes, instead of using the input for +these nodes. Also, it makes lookups in the database much faster, as we will be +able to use an array instead of a hash table.|#) + +@chunk[ + Index] + +@subsection{The queues of placeholders} + +@chunk[ + (make-placeholder root-expr ...)] @chunk[ - (inst fold-queue-sets-immutable-tags - Integer - Void - String - (List 'a Integer String))] + (fold-queues + [(mapping [e : ] get-tag Δ-queues) + : + 'todo!] + ...)] + + +@section{Making placeholders} + +@; TODO: make a template library that implicitly creates temporaries for +@; foo/bar, when foo is a syntax parameter. + +@chunk[ + (define-temp-ids mapping "~a/make-placeholder")] + +@chunk[ + (define-temp-ids mapping "~a/placeholder-type")] + +@chunk[ + (define-type mapping/placeholder-type (List 'mapping param-type ...)) + + (: mapping/make-placeholder (→ param-type ... mapping/placeholder-type)) + (define (mapping/make-placeholder [param : param-type] ...) + (list 'mapping param ...))] + +@section{Temporary fillers} + +@chunk[ + Any] + +@chunk[ + Any] + + +@section{Bits and pieces} + +@chunk[ + (define-syntax/parse + + #'(begin + (begin ) ... + ))] @section{Conclusion} @@ -224,10 +294,12 @@ ones as these placeholders are discovered inside incomplete nodes. (require (for-syntax syntax/parse racket/syntax "../lib/low-untyped.rkt") - "queue.lp2.rkt" + "fold-queues.lp2.rkt" "rewrite-type.lp2.rkt" "../lib/low.rkt") + (provide fold-queues) + (provide make-graph-constructor) )]