# HG changeset patch # User Adam Chlipala # Date 1290372204 18000 # Node ID 80bff6449f4162fb16a7c1f9035f6a0d3ad8ec0f # Parent 4172863d049df21725cf8619703cde41b20a8dc6 Fix a bug in C list unurlification diff -r 4172863d049d -r 80bff6449f41 lib/ur/list.ur --- a/lib/ur/list.ur Sat Nov 20 10:45:22 2010 -0500 +++ b/lib/ur/list.ur Sun Nov 21 15:43:24 2010 -0500 @@ -308,6 +308,20 @@ sort' ls end +val nth [a] = + let + fun nth (ls : list a) (n : int) : option a = + case ls of + [] => None + | x :: ls' => + if n <= 0 then + Some x + else + nth ls' (n-1) + in + nth + end + fun assoc [a] [b] (_ : eq a) (x : a) = let fun assoc' (ls : list (a * b)) = diff -r 4172863d049d -r 80bff6449f41 lib/ur/list.urs --- a/lib/ur/list.urs Sat Nov 20 10:45:22 2010 -0500 +++ b/lib/ur/list.urs Sun Nov 21 15:43:24 2010 -0500 @@ -71,6 +71,8 @@ val sort : a ::: Type -> (a -> a -> bool) (* > predicate *) -> t a -> t a +val nth : a ::: Type -> list a -> int -> option a + (** Association lists *) val assoc : a ::: Type -> b ::: Type -> eq a -> a -> t (a * b) -> option b diff -r 4172863d049d -r 80bff6449f41 src/cjr_print.sml --- a/src/cjr_print.sml Sat Nov 20 10:45:22 2010 -0500 +++ b/src/cjr_print.sml Sun Nov 21 15:43:24 2010 -0500 @@ -861,7 +861,7 @@ space, string "+=", space, - string "3, NULL) : ((!strncmp(request, \"Cons\", 4) && (request[4] == 0 ", + string "3, (*request == '/' ? *request++ = 0 : 0), NULL) : ((!strncmp(request, \"Cons\", 4) && (request[4] == 0 ", string "|| request[4] == '/')) ? (request", space, string "+=", @@ -895,7 +895,7 @@ newline, string ":", space, - string ("(uw_error(ctx, FATAL, \"Error unurlifying list\"), NULL))));"), + string ("(uw_error(ctx, FATAL, \"Error unurlifying list: %s\", request), NULL))));"), newline], string "}", newline,