[ prog / sol / mona ]

prog


Help on the Way

1 2022-03-28 19:35

If you need help with programming, advice, recommendations, and so on and so on, just post here and the brightest minds of SchemeBBS will surely help you!

2 2022-03-29 03:36

Does P = NP?

https://textboard.org/prog/298

3 2022-04-07 08:25

I want an robot AI waifu.

4 2022-04-07 15:25

why is this not working??

(define (fizzbuzz n)
	(cond
		(zero? (remainder n 5)) 'fizz
		(zero? (remainder n 3)) 'buzz
		else n))

(map fizzbuzz '(1 2 3 4 5 6 7 8 9 10))
5 2022-04-07 19:39

>>4
Because COND works a bit differently (it is one of the special forms): https://api.call-cc.org/5/doc/scheme/cond or https://schemers.org/Documents/Standards/R5RS/

You need to do it like this:

#!/usr/bin/guile -s
!#
;coding: utf-8
;; those 3 lines above are Guile specific stuff:
;; https://www.gnu.org/software/guile/manual/html_node/The-Top-of-a-Script-File.html


; (you can replace the square brackets with regular parenthesis)
(define (fizzbuzz n)
	(cond
		[(zero? (remainder n 5)) 'buzz]
		[(zero? (remainder n 3)) 'fizz]
		[else n]))

(map fizzbuzz '(1 2 3 4 5 6 7 8 9 10))

More about special forms (in general): https://www.cs.utexas.edu/ftp/garbage/cs345/schintro-v14/schintro_17.html

6 2022-04-07 20:07

'(1 2 3 4 5 6 7 8 9 10)

Might want to look up the iota procedure.

7 2022-04-08 01:10
(import (srfi srfi-41))    
(define fizzbuzz
  (stream-map
    (lambda (x y) (or x y)) 
    (stream-constant #f #f "fizz" #f "buzz" "fizz" #f #f "fizz" "buzz" #f "fizz" #f #f "fizzbuzz" )
    (stream-from 1)))
(stream-for-each (lambda (x) (format  #t "~A\n" x)) (stream-take 100 fizzbuzz))
8 2022-04-08 10:18

#f #f "fizz" #f "buzz" "fizz" #f #f "fizz" "buzz" #f "fizz" #f #f "fizzbuzz"

Instead of writing this out manually, compute it and apply it to stream-constant.

9 2022-04-08 11:19

Is using or like that conventional in Scheme? Once I tried that in Python and was told not to exploit unintentional features.

10 2022-04-08 14:47

>>9
Like what? Instead of `(if x x y)`? Sure, that is common.

11 2022-04-08 15:06

>>9

Once I tried that in Python and was told not to exploit unintentional features.

I don't do Python, but it doesn't seem to me like an "unintentional feature":

https://docs.python.org/3/reference/expressions.html#boolean-operations
Note that neither and nor or restrict the value and type they return to False and True, but rather return the last evaluated argument. This is sometimes useful, e.g., if s is a string that should be replaced by a default value if it is empty, the expression s or 'foo' yields the desired value.

12 2022-04-08 15:39

>>10-11
Oh right, in my case I was using and to guard a function with side effect. I guess in Scheme I would have just used when or unless.

13 2022-04-08 17:18

>>8
And to compute it you need to write...

14 2022-04-08 18:57

>>13
Something like this:

(define (fizzbuzz n)
  (with-output-to-string
    (lambda ()
      (when (zero? (remainder n 5)) (display "fizz"))
      (when (zero? (remainder n 3)) (display "buzz"))
      (when (zero? (port-position (current-output-port))) (display n)))))
15 2022-04-08 20:05

>>13

And to compute it you need to write...

Two stream-constants with k-1 #fs and one "meme", stream-map over them with an appropriate lambda and take the lcm into a list for apply.

16 2022-04-08 21:17

>>15
Biting for another meme thread?

17 2022-04-09 10:29

>>16
The difference between "another meme thread" and not hardcoding a precomputed '#f #f "fizz" #f "buzz" "fizz" #f #f "fizz" "buzz" #f "fizz" #f #f "fizzbuzz"' should become obvious upon a moment of reflection.

18 2022-04-11 06:22

How to deal with people who put the closing paren on its own line?

19 2022-04-11 09:58

>>18
Learn how to use a code formatter.

20 2022-06-02 07:35

>>1

I get help from real people. http://www.datacamp.com

21 2022-06-04 08:23

Calculating qualities. 300 000 page views regularly.
600 grand yearly.
how to even decide, the "content style", qualities.

22 2022-06-04 09:50

i just need to know the right stuff to the right number. also maybe why

23 2022-06-04 11:12

Help! Why is Scheme hopelessly broken? I cannot even get the answer to 1 + 1

Guile:

scheme@(guile-user)> 1 + 1
$1 = 1
$2 = #<procedure + (#:optional _ _ . _)>
$3 = 1
scheme@(guile-user)>

MIT Scheme:

1 ]=> 1 + 1

;Value: 1

1 ]=> 
;Value: #[arity-dispatched-procedure 12]

1 ]=> 
;Value: 1

1 ]=>
24 2022-06-04 11:36 *

>>23
You forgot to switch to your blub syntax:

scheme@(guile-user)> ,L ecmascript
Happy hacking with ECMAScript!  To switch back, type `,L scheme'.
ecmascript@(guile-user)> 1 + 1;
$1 = 2
25 2022-06-04 12:14

>>24
What blub? Lisp is the ultimate blub language, but the clueless lispers are too blind, arrogant, and out of touch to realize it. I feel sorry for those Lisp programmers who suddenly realize that they have been using a blub language all along. The sanatoriums may not be able to help these poor people. As they say, ignorance is bliss.

26 2022-06-04 12:18

>>24
Does that make Node.js obsolete?
I generally feel sorry for the oppressed Schemers and their poor programming language, but now I feel happy that they have a way to escape into the free land of JavaScript where they are able to taste freedom for the first time.

To switch back, type `,L scheme'.

Never!

27 2022-06-04 20:15 *

>>26

Does that make Node.js obsolete?

No, Node.js is still required to easily get your files https://textboard.org/prog/422 overwritten by malware.

Furthermore: https://www.gnu.org/software/guile/manual/html_node/ECMAScript.html

ECMAScript was not the first non-Schemey language implemented by Guile, but it was the first implemented for Guile’s bytecode compiler. The goal was to support ECMAScript version 3.1, a relatively small language, but the implementor was completely irresponsible and got distracted by other things before finishing the standard library, and even some bits of the syntax. So, ECMAScript does deserve a mention in the manual, but it doesn’t deserve an endorsement until its implementation is completed, perhaps by some more responsible hacker.

In the meantime, the charitable user might investigate such invocations as ,L ecmascript and cat test-suite/tests/ecmascript.test.

28 2022-06-05 03:21

>>27

Node.js is still required to easily get your files https://textboard.org/prog/422 overwritten by malware.

That's a great way to discourage the use of JavaScript. Lispers should launch more of such attacks on the JavaScript ecosystem, as retaliation for the publication of the heretical JSICP.

29 2022-06-05 12:44

>>28
That will just seed hatred and hostility. It would be more productive to write more useful software in Lisp than there is written in JavaScript and show its simplicity and hackability to people.

30 2022-06-05 13:13

>>29 there is no useful software written in javascript.
Lisp could only replace js if people decided to wrote harmful software in it.

31 2022-06-05 13:32

how do i make C program that saves gif. super thank you

32 2022-06-05 14:51

>>31
With `fwrite()`.

33 2022-06-05 14:56

>>30
But then there will be no software written in JavaScript and a bunch of harmful software written in Lisp. It doesn't seem advantageous.

BTW there is useful software like OnlyOffice or Jitsi.

34 2022-06-05 20:07

>>31
https://sourceforge.net/p/giflib/code/ci/master/tree/

35 2022-06-05 22:12

>>35 so any c compiler knows how to fwrite

36 2022-06-05 22:28

>>35 so any c compiler knows how to fwrite

37 2022-06-16 06:34

How do I find good programming books? Most that I come across end up being garbage.

38 2022-06-16 07:27

>>37
I could reveal over thirty reading recommendations, if that would help.

39 2022-06-16 07:51

>>37

man man
40 2022-06-16 12:58

>>37
Avoid anything that says it will teach you something quickly ("learn foo in 24 days" or similar) and avoid books that are written for beginners.

41 2022-06-16 13:02

I feel like most books are written for beginners, even those that claim not to be.

42 2022-06-16 18:17

Is this guide fine? http://jaredkrinke.github.io/learn-scheme/index.html

I'm reading it.

43 2022-06-17 02:47

is not there any other windows software written in mit-scheme besides edwin?

44 2022-06-17 04:46

>>42
I recommend Teach Yourself Scheme in Fixnum Days.
https://ds26gte.github.io/tyscheme/

Other free Scheme programming books:
https://ebookfoundation.github.io/free-programming-books/books/free-programming-books-langs.html#scheme

45 2022-06-17 07:49

>>44

Thank you.

46 2022-06-17 08:46

>>45
But to reach an intermediate level in Scheme, it may be necessary to read SICP, Lisp in Small Pieces, and one of the Scheme specifications (e.g. R5RS or R7RS-small).

47 2022-06-17 12:32

>>46

R5RS or R7RS-small

Are we stuck in a python2/3 situation?

48 2022-06-17 13:29

>>46
No, Scheme has always been fractured due to incompatibilities between implementations.

There is currently an ideological split between big Scheme (R6RS) and small Scheme (R5RS/R7RS-small).

49 2022-06-17 13:32

>>43

We no longer support OS/2, DOS, or Windows, though it's possible that this software could be used on Windows Subsystem for Linux (we haven't tried).

https://www.gnu.org/software/mit-scheme/

50 2022-06-18 01:35

>>49
but that has nothing to do with the subject...

51 2022-06-21 06:50

>>38
Please do.

52 2022-06-21 07:56

>>51
Okay. They're on this website: http://verisimilitudes.net

Articles are arranged as YYYY-MM-DD or ISO 8601. Every date ending in fifteen since 2019 is a review. Not all reviews concern programming. Everything is also available over Gopher.

Follows are some of my favourite reviews:
http://verisimilitudes.net/2019-07-15
http://verisimilitudes.net/2019-08-15
http://verisimilitudes.net/2020-09-15
http://verisimilitudes.net/2020-10-15
http://verisimilitudes.net/2022-01-15
http://verisimilitudes.net/2022-06-15

53 2022-06-21 09:00

>>52

Why madmen still use light themes these days? Your website is unreadable without browser plugins which fix your CSS colors.

54 2022-06-21 09:34 *

Don't fall for the meme, dark themes are objectively worse for your eyes.

55 2022-06-21 10:03

>>54

What meme? I feel how my eyes are aching from light background. It's not a meme, it's classic palette since TTY terminals are "dark themed". Light theme is invented by stupid GUI bloat advocates like Jobs and Gates.

Poweruser CLI-dweller hygiene requires dark theme.

56 2022-06-21 11:02

>>53
I have no problem with reading light themes or dark themes. Works for me.

57 2022-06-21 11:39

>>56

Why should I care about you? Should I maybe also care about Windows users and stop talking about GNU/Linux not to hurt their feelings?

It's a fact that many people strongly prefer dark theme even during daytime, otherwise there wouldn't exist so many browser plugins like DarkThemeCSS. A blogger must be an idiot to ignore such strong preference among potential readers.

58 2022-06-21 11:47

It's a fact that dark themes are worse for your eyes than light themes. If you want to harm yourself, that's your choice. But you can't demand that other's eyes should be damaged too, just because you happen to be an idiot.

59 2022-06-21 12:52

>>57
People who cannot adapt to a wide range of stimulus are inherently weak.

60 2022-06-21 13:06 *

not using solarized dark or the objectively superior solarized light.

61 2022-06-21 13:52

>>58

Proofs or fuck off.

>>59

Why women don't adapt to rapist's dick in their anus? Inherently weak, probably.

62 2022-06-21 13:52

Can you posts studies supporting your statement. I want to know if using dark theme is necessary/

63 2022-06-21 15:03

>>62

I never stated anything about "objective facts" like you did. My rant is about my own comfort enforced with the fact that many people prefer dark theme.

But if you are talking about "objectivity", feel free to provide links to medical research. Otherwise fuck off with your fake "objectivity".

Anyway, since you are a moron, I can come up with a nice link myself: https://ssb22.user.srcf.net/css/dark.html

All dark theme cons listed there are either situational or would never happen with proper web design i.e. large fonts.

64 2022-06-21 15:06

>>63
Sorry that was my first post in the thread. This proves that er need names or randomized IDs to recognize posters.

65 2022-06-21 15:08 *

enforced

I mean, empowered.

66 2022-06-21 15:11

>>64
No, IDs are bad for discussion, also they are not ideal for detecting identity.

Sorry, my reply is not personally to you, but for morons above, who are talking about white background "objectively better for health" with no proofs.

67 2022-06-21 16:03

ur a mron. heccin dummy!

68 2022-06-21 16:11

>>67

:-*

69 2022-06-21 16:47

day

light mode

night

dark mode

https://dl.acm.org/doi/fullHtml/10.1145/3357251.3357584
https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=9363189

70 2022-06-21 16:49 *

>>69
more: https://www.nngroup.com/articles/dark-mode/

71 2022-06-21 17:02

>>69
Too stereotypical. My room "home office" is dark during day. I don't work outdoors.

72 2022-06-21 17:29

>>57

A blogger must be an idiot to ignore such strong preference among potential readers.

Just read it over Gopher then, using a terminal with the desired preferences, and stop with this nonsense.

73 2022-06-21 18:03

>>72

I can read gopher or www version through Emacs or, let's say, lynx, or just click Ctrl+Shift+A in FF to add this light-themed toilet to DarkReader, but this doesn't do design of that blog any better.

74 2022-06-21 19:24 *

Why is it always the dark theme moles that whine about light themes? Will your eyes fly out of the eye sockets and into your asshole if the colors are too bright?

75 2022-06-21 20:46

>>74

My dick will fly into your asshole if you don't shut up and apologize for your behavior.

76 2022-06-22 06:37

my anus will wrap around your dick unless you allow such behavior

77 2022-06-22 07:23

>>75
Good luck with that. I don't even have my 455 TCP open.

78 2022-06-22 13:12

>>74
because they are paupers lost in the darkness
they can not bear us, beacons of light

79 2022-06-25 01:52

does anyone have the book "the schematics of computation" by vincent manis?
i have never seen it circulating on the interwebz... by the way, his scheme implementation for windows (winscm) is even more rare

80 2022-06-25 01:56

>>43

https://github.com/alban-read/Scheme-Windows-Tiled-Shell

not mit-scheme but give it a try :3

81 2022-06-25 02:20

>>80

https://www.cs.bgu.ac.il/~elad/GALAPAGOS/

or even better, jaffer's scm

82 2022-06-25 04:39

I am trying to solve SICP Exercise 1.16. Here is my solution:

(define (fast-expt-iter b n)
  (cond ((= n 1) b)
        ((even? n) (fast-expt-iter (square b) (/ n 2)))
        (else (fast-expt-iter (square b) (- n 1)))))

I can't find any error when I work it out on paper myself; but when I run it I get the wrong answer.
What am I missing here?

83 2022-06-25 06:00

>>82

keep, along with the exponent n and the base b, an additional state variable a, >and define the state transformation in such a way that the product ab^n is >unchanged from state to state.

Aren't you missing the 'a' variable?

84 2022-06-25 08:39

>>82
You change b== the same way in both cases but change ==n differently, does that make sense?

85 2022-06-25 14:09

>>82
Let X{t} be the value of the local variable X after t steps. Let X be the unmodified value passed to you from the outside. Initial conditions:

a{0} = 1, b{0} = b, n{0} = n

Invariant:

a{0} * b{0}^n{0} = b^n

Recall that when deconstructing a number into bits with parity or modulo 2 and right shift or quotient 2, you proceed from the LSB to the MSB. Keeping that in mind, the algorithm can be recovered from the invariant by the usual process of assuming you've already performed k steps correctly and you just need to perform step k+1. In other words you just need a state transformation:

(a{k}, b{k}, n{k}) --> (a{k+1}, b{k+1}, n{k+1})

The invariant assures you that:

a{k} * b{k}^n{k} = b^n

Therefore if n{k} = 0 then a{k} = b^n and you're done. Otherwise you're in this situation:

        n{k}
+-------------------+
|                   |
+---------------+   +-----------+
|bit bit bit bit|bit|bit bit bit| = n
+---------------+ ^ +-----------+
     n{k+1}       |     k bits
               current

The bit deconstruction equations can be read off the diagram:

n{k+1} = n{k} // 2   [eq1]
current = n{k} mod 2 = 0 or 1
2 * n{k+1} + current = n{k}
2 * (n{k} // 2) + (n{k} mod 2) = n{k}

where // stands for integer division. The next invariant that you must satisfy:

a{k} * b{k}^n{k} = b^n = a{k+1} * b{k+1}^n{k+1}

Use [eq1]:

a{k} * b{k}^n{k} = a{k+1} * b{k+1}^(n{k} // 2)

You need to account for the halving of the exponent to maintain the invariant. You can do so in either a{k+1} or b{k+1}. But a{k+1} has no exponent applied to it, so it would need to compensate with its own internal exponentiation using some dependence on n{k}. This would make the process recursive, but the exercise https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-11.html#%_thm_1.16 requires the process to be iterative. So you account for the halving of the exponent in b{k+1}. To account in a base for the halving of its exponent you square the base, as the exercise already suggests.

b{k+1} = b{k}^2   [eq2]

Plug it back into the invariant:

a{k} * b{k}^n{k} = a{k+1} * (b{k}^2)^(n{k} // 2)

To compute nested powers multiply the exponents.

a{k} * b{k}^n{k} = a{k+1} * b{k}^(2 * (n{k} // 2))

Use the [eq1] group to rewrite the exponent:

a{k} * b{k}^n{k} = a{k+1} * b{k}^(n{k} - (n{k} mod 2))

Simplify to get a{k+1}:

a{k+1} = a{k} * b{k}^(n{k} mod 2)

You don't need to actually exponentiate here because (n{k} mod 2) can only be 0 or 1.

a{k+1} = | a{k}        if (n{k} mod 2) = 0
         | a{k} * b{k} if (n{k} mod 2) = 1
                                             [eq3]
a{k+1} = | a{k}        if current bit = 0
         | a{k} * b{k} if current bit = 1

Together [eq1], [eq2] and [eq3] specify the state transformation. This sort of technique can be used in general to recover algorithms from invariants.

86 2022-06-25 19:58

>>83-85
Thank you for your help. I believe I have found a solution:

(define (fast-expt-iter b n a)
  (cond ((= n 0) a)
        ((even? n) (fast-expt-iter (square b) (/ n 2) a))
        (else (fast-expt-iter b (- n 1) (* a b)))))

Observing if n is even:
```b^n = (b^2)^n/2```
and do:
```(b, n, a) -> (b^2, n/2, a)```

Observing if it is not:
```b^n = b*b^n-1```
and do:
```(b, n, a) -> (b, n-1, a*b)```

Where it is seen:

   (fast-expt-iter 2 6 1)
-> (fast-expt-iter 4 3 1)
-> (fast-expt-iter 4 2 4) 
-> (fast-expt-iter 16 1 4)
-> (fast-expt-iter 16 0 64)
-> 64

I was a bit lost when >>85-san went on about deconstructing the bits, but I will thank the good explanation of the state transformation for helping me work this out.
Orders of growth and the nature of these iterative processes are still a bit arcane to me, but I feel as though the fog has lifted. Thank you!

87 2022-08-29 20:51

Does anyone actually way Lisp the canonical way, top-down, first writing the highest-level parts and then filling in the details?

88 2022-08-31 01:42

>>87
Why is top-down considered the canonical way?
Imagine in the future: one or two highly paid programmers using their creativity to write the highest-level parts, leaving many minimum wage programmers with the menial task of filling in the blanks. This is similar to all the "fill in the blanks" homework for schoolchildren. Great for reducing costs.

89 2022-09-13 18:06

Are small-step semantics somehow connected to continuation-passing style? It reminds me of that.

90 2022-09-13 20:14 *

>>89
https://rolph-recto.github.io/posts/2016-12-26-implementing-callcc.html

91 2022-09-23 06:53

https://srfi.schemers.org/srfi-236/srfi-236.html
Why is this implemented as a macro? Wouldn't this work:

(define (perform . l) (begin))
92 2022-10-04 06:45

I wish you could comment bash like this:

find . -type f -print0 \           # list all files
    | xargs -0 -n1 ffprobe 2>&1 \  # extract media information
    | awk '...' \                  # do something with it
    | less
93 2022-10-05 08:56

>>92
You don't need to break lines on pipes.

find . -type f -print0    |  # list all files
xargs -0 -n1 ffprobe 2>&1 |  # extract media information
awk '...'                 |  # do something with it
less

Should work just fine.

94 2022-10-08 20:35

>>93
But it does not look as cool as the other.

95 2022-10-08 23:34

>>94
What do you mean? It looks way cleaner to me.

96 2022-10-29 23:14

>>91
Probably, but then you don't get special form evaluation semantics which are likely intended.

97 2022-10-30 08:11

How do i stop getting stuck in autistic pits with designing software while not giving up and making something horrible?

98 2022-10-30 13:35

>>97
Stop using OOP.

99 2022-10-30 19:56

>>98
I use functional

100 2022-10-31 03:40

Luk mom dubs

101 2022-10-31 07:42

>>97
Make something horrible first. If you understand why your code is so horrible, then I'd expect that you should be able to refactor the code so it sucks less.

102 2022-10-31 18:39

>>101
I have no will to afterwards and will most likely trash it then repeat the cycle

103


VIP:

do not edit these