Logic programming library development log

True. The above was just to see if I'm correctly interpreting SICP flatmap. To make it a set one may e.g. insert Streams extended script pic (37) for example. Or check if GCD = 1 with every fraction calculated:

Streams extended script pic (38)

(using GCD from the APL library, plus the weird but convenient map over keep from map over stream block :slight_smile: )

Uhhhh, if you were taking the rational numbers themselves, but taking, say, 1/2 and 2/4 and saying they are UNIQUE, even though they REPRESENT the same number, then it's still a set. In fact, Cantor's diagonal argument USES DUPLICATES(1/1, 2/1, 1/2, 1/3, 2/2, 3/1, ...)

Maybe initially but Wikipedia claims "Fractions which can be simplified are left out:"

There's the kicker. CLAIMS. Doesn't mean that's true.

But the definition of sets disallows duplicates - I'm not aware of any notion of countability for multisets.

Though an interesting discussion ...

My 2 cents
  1. an element can only be in a set once;
  2. e.g. 1/2 and 2/4 are different representations of the same number; so ...
  3. depending on the perspective (form vs. value) they can either both be separate members of a set, or they must be considered the same member;
  4. I lean towards considering the Rationals a set of values, but I fully understand the alternative perspective;
  5. In the end, what counts (granted, a corny pun) is that either way the Rationals are countable; it doesn't matter by which index number each Rational is referred to.

... it's off-topic. :bomb:

Ok, neither have I.

No it's not, and that's actually a good point.

I think you left something out here?

No mistake! You can actually do that:

Like you can also do:

Ah, okay.

My life has been too hectic lately for me to have a solid chunk of time to look at the library, but I'll get there...

No problem as far as I’m concerned. One’s personal life, and health, should always be one’s top priorities.

Getting back to logic programming and SICP section 4.4 ... since, as I have understood, Snap! 's list and Scheme's pair are somewhat different, how would:

(cons variable value)

(par. 4.4.4.8)

... translate to Snap! ?

  1. Logic programming SICP script pic, or
  2. Logic programming SICP script pic (1), or even
  3. Logic programming SICP script pic (2)|405x42, 5=100%

i think I have found the solution myself: it’s up to me to decide - as long as I’m consistently adhering to the same structure.

Yeah, you can do it however you want. But you're a little constrained by the fact that IN FRONT OF will only accept a list as its second input, whereas cons lets you put anything in the cdr. So for example a point on the plane which would naturally be (cons xposition yposition) in Lisp would have to be (LIST ...) in Snap!. If the list is stored as a Lisp-style linked list, that'd be two pairs rather than just one.

Would this be the Snap! translation of LISP / Scheme’s cons function?

No, because that's not invertible. It has to be that
(car (cons a b)) = a
(cdr (cons a b)) = b
and that doesn't work for cdr, because if you see (list a (list b)) you don't know whether its cdr is supposed to be b or (list b).

I've actually been wondering if there's a way to create imperfect lists, I.E. '(1 . 2).

No. That was a decision made in Scratch long ago, which we haven't, so far anyway, seen fit to change. I think that if we were ever to introduce pair mutation (SET ALL BUT FIRST OF _ TO _) (note the imperfect tense!), we might consider non-list pairs at the same time. Neither is very likely.

OK. Then I guess the only feasible general translation of a LISP / Scheme pair is a Snap! list of two items, while LISP / Scheme's list would translate to building nested 2-item lists in Snap!, much like the structure of streams. Is that right?

Yes, exactly.

I have a few questions about procedures on SICP section 4.4.4.2., paragraph "filters":

(define (lisp-value call frame-stream)
_ (stream-flatmap
_ _ (lambda (frame)
_ _ _ (if (execute
_ _ _ _ _ (instantiate
_ _ _ _ _ call
_ _ _ _ _ frame
_ _ _ _ _ (lambda (v f)
_ _ _ _ _ _ (error "Unknown pat var: LISP-VALUE" v))))
_ _ _ _ (singleton-stream frame)
_ _ _ _ the-empty-stream))
_ _ frame-stream))

  • What does call stand for? (is it a predicate?)
  • I was also puzzled by lambda (v f), but I think I know what it stands for now: the lambda function is an unbound variable handler that will ignore its second input - please correct me if I'm wrong.

(define (execute exp)
_ (apply (eval (predicate exp) user-initial-environment)
_ _ _ _ _ (args exp)))

  • Is apply equivalent to reportcall in Snap! ?
  • what is eval equivalent to in Snap! ?
  • what is the user-initial-environment?
  • where does (args exp) come in?

Another question, about sect. 4.4.4.7: what would symbol? translate to in Snap! ?