($ contains sublist $) and periods

I’m running this unit test:

(test #short-range-scan)
	(line) (short range scan)
	(collect words) (short range scan) (into $Words)
	(log) { $Words }
	%%($Words contains sublist [3 . q])
	%%($Words contains sublist [5 . . . . . q])
	%%($Words contains sublist [6 . . . . e])
	($Words contains sublist [heading: 315])
	($Words contains sublist [warp gradient: 4])
	($Words contains sublist [position: 3 - 4 \/ 5 - 6])
	($Words contains sublist [energy: 932 , 4 crystals online])

…with this output:

Testing #short-range-scan:
     1 2 3 4 5 6 7 8 9 10
  1  . . . . . . . . . .   Earth Date: 051230 Mar 73
  2  . . . . . . . . * .   Alert Status: GREEN
  3  . q . . . . . . . .   Quadrant: 103-37 (unit tests)
  4  . . . . . . . . . .   Position: 3-4 / 5-6
  5  . . . . . q . . . .   Destination: not set
  6  . . . . E . . . . .   Heading: 315
  7  . . . . . . . . . .   Warp Gradient: 4
  8  . . . . . . . . . .   Energy: 932, 4 crystals online
  9  . . . . . . . . . .   Torpedoes: 10, not armed
  10 . . . . . . . . . .   Shields: down, 100%

[1 2 3 4 5 6 7 8 9 10 1 . . . . . . . . . . earth date: 051230 mar 73 2 . . . .
 . . . . * . alert status: green 3 . q . . . . . . . . quadrant: 103-
37 ( unit tests ) 4 . . . . . . . . . . position: 3 - 4 / 5 -
 6 5 . . . . . q . . . . destination: not set 6 . . . . e . . . . . heading: 31
5 7 . . . . . . . . . . warp gradient: 4 8 . . . . . . . . . . energy: 932 , 4 
crystals online 9 . . . . . . . . . . torpedoes: 10 , not armed 10 . . . . . . 
. . . . shields: down , 100 %]
Passed!

…and when I uncomment any of the commented-out ($ contains sublist $) queries with periods in them, the query fails and the test fails, despite me being clearly able to see that the list does, in fact, contain the sublist. What’s going on here? (The same thing happens with vertical bars.)

Without having access to the (short range scan) code I can’t be sure, but am I right that you added in a backslash space to pad the spacing between 3 and . q, etc? It seems that that gets translated into a @\s dictionary word, so [3 . q] isn’t a sublist of [3 \s . q] because of the space word. That’s what I can figure out from messing around a bit in dgdebug at least, if I’m right the fix is to do ($Words contains sublist [3 \s . q]), at least I think?

1 Like

Nope, still fails. [3 \s . q] fails, [3 \s . \s q] fails, [3 @. q] fails, and I’m at sea about what else to try.

Firstly I don’t have a solution for this as yet.

I don’t think the periods are the issue here, it’s the numbers, or more accurately a duplication of numbers in the main list. This is what I think is happening: when the ‘contains sublist’ check is made the library in turn splits the sublist into heads and tails [3] and [. q] and then looks for [3] in the main list to start checking for the sublist. It finds it but it is the first ‘3’ in the main list. Not the 3 we are looking for, as the rest of the sublist doesn’t follow this 3 the check fails. As a test if you change the 3 in the main list and the sublist check to 33 the check passes.

($Words contains sublist [33 . q])

This also passes.

($Words contains sublist [10 1 . . . . .])

Not much help for a solution I’m afraid, but it may help narrow one down, I’ll keep looking.

1 Like

Does this work?

($List contains sublist [$Head | $Tail])
	*(split $List by [$Head] into $ and $Rest)
	(append $Tail $ $Rest) (log) {$Head $Tail $ $Rest}

Add it to your code, it replaces the ‘contains sublist’ library routine. The only change is to change the split into a multi-query.

1 Like

Yep, that did the trick. You win the Stellar Union Distinguished Engineering Medal. :slight_smile:

1 Like