The curly-infix definition isn't clear about what happens to *improper* lists, and our implementation crashes in certain cases when handed an improper list. We need to nail that down as a definition, and implement that, and in particular ensure that we don't crash on input (!).
In our current implementations (both kernel.scm and the simplified srfi implementation), the behavior is currently as follows. The expression: {3 + 4 . x} produces: (nfx 3 + 4 . x) And this expression: {3 + 4 + . x} Crashes the implementation with: ERROR: Wrong type (expecting pair): x Crashing is obviously NOT okay. So what, exactly, *should* be the semantics here? I think that if you have an improper list, the last ("improper") item should count as length 1. That means that the implementation would be working correctly for the first example; "{3 + 4 . x}" has length 4, so the "nfx" rule is used, transforming it to (nfx 3 + 4 . x). This would mean, also, that {3 + 4 + . x} should be transformed to (+ 3 4 . x) instead of crashing. This is an arguably consistent extension, and it would provide a simple mechanism to provide an option to an infix operation. This turns out to be an easy two-line change to the implementation, attached below. Thoughts? --- David A. Wheeler ============================ --- srfi-neoteric.scm 2012-08-17 08:30:11.016314393 -0400 +++ ,1 2012-08-17 09:08:43.840172344 -0400 @@ -99,12 +99,13 @@ (define (even-and-op-prefix? op lyst) (cond ((null? lyst) #t) ((not (pair? lyst)) #f) ; Not a list. ((not (eq? op (car lyst))) #f) ; fail - operators not the same ((null? (cdr lyst)) #f) ; fail - wrong # of parameters in lyst. + ((not (pair? (cdr lyst))) #t) ; Improper list, count last as an item (#t (even-and-op-prefix? op (cddr lyst))))) ; recurse. ; Returns true if item is member of lyst, else false. (define (ismember? item lyst) (pair? (member item lyst))) @@ -118,13 +119,13 @@ ; this way for performance) (symbol? (cadr lyst)) ; 2nd parameter must be a symbol. (even-and-op-prefix? (cadr lyst) (cdr lyst)))) ; true if rest is simple ; Return alternating parameters in a lyst (1st, 3rd, 5th, etc.) (define (alternating-parameters lyst) - (if (or (null? lyst) (null? (cdr lyst))) + (if (or (not (pair? lyst)) (not (pair? (cdr lyst)))) lyst (cons (car lyst) (alternating-parameters (cddr lyst))))) ; Transform a simple infix list - move 2nd parameter into first position, ; followed by all the odd parameters. Thus (3 + 4 + 5) => (+ 3 4 5). (define (transform-simple-infix lyst) ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Readable-discuss mailing list Readable-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/readable-discuss