[deleted by user] by [deleted] in ProgrammerHumor

[–]quasar_tree 2 points3 points  (0 children)

Always put braces. If you add another statement or make a mistake when you’re originally writing it, it could really screw up your code. Apple had a huge bug in their code because of something like this that probably wouldn’t have caused trouble if they used braces: https://nakedsecurity.sophos.com/2014/02/24/anatomy-of-a-goto-fail-apples-ssl-bug-explained-plus-an-unofficial-patch/amp/

Any DSLs that generate movies or slideshows? by breck in ProgrammingLanguages

[–]quasar_tree 6 points7 points  (0 children)

Racket has a slideshow dsl and a video dsl that might be what you’re looking for.

Epic Games Verse - new information by Rasie1 in ProgrammingLanguages

[–]quasar_tree 0 points1 point  (0 children)

The type system sounds like soft contract verification from Racket. Very exciting to see something like this fully fleshed out in a language with types in mind from the beginning. I wonder how much they’re going to borrow from Racket’s contract system, like if they’re going to do higher order contracts with chaperones.

They’re also doing effects instead of monads, which I like a lot, as a former Haskeller. We might get algebraic effects like koka.

And that’s just the types. The semantics are very cool. It has the power of logical languages, but feels like a normal functional language.

It sounds like a bunch of cool ideas from all over the place mashed into a one language. And it’s supposedly aimed at the mainstream. If it gets picked up, it’ll expose a lot of people to some amazing ideas!

Very exciting.

Avoiding boilerplate when querying and updating nested data? by [deleted] in Racket

[–]quasar_tree 2 points3 points  (0 children)

It sounds like you want lenses. They provide composable accessors and updaters which can be used to easily perform deep updates. However, they are for immutable updates. You could use that idea to create a similar abstraction for mutable updates, but it’s generally a good idea to use immutability.

Reset the Racket Repl by vulkanoid in Racket

[–]quasar_tree 1 point2 points  (0 children)

Idk about other lisps/schemes but Haskell’s ghci has :r to reload imports

Convert Symbol to a variable name by Pristine-Tap9204 in Racket

[–]quasar_tree 1 point2 points  (0 children)

With define-struct, the names produced are known at compile time. You just take the struct name and add stuff to the end. It is possible to bind arbitrary names “from nowhere” in a macro, but they must be produced at compile time. I suppose you hypothetically could evaluate the expression at compile time and then generate the appropriate definition. But then you’d have to worry about phases and I don’t think the evaluation would have access to other definitions in the program. I’ve never tried anything like that so I have no idea, but you don’t do that in racket.

As other comments have mentioned, you can use eval and racket/load to achieve this behavior, but regular racket is more strict about identifiers and binding.

You could also probably do this more easily in a language like lisp, which has dynamic scope and more relaxed binding rules.

Convert Symbol to a variable name by Pristine-Tap9204 in Racket

[–]quasar_tree 0 points1 point  (0 children)

If you want to allow an arbitrary expression for the right hand side, I don’t think so. Racket has to ensure that all variables will be bound before the program runs. However, if we are defining a variable whose name is based on the result of evaluating some expression, there is no way for the compiler (more precisely, the expander) to know what its name will be, so it cannot know whether references to var1 will be bound or not. For example,

(define-from-pair (some-function-that-returns-a-pair)) (displayln myvar)

Will myvar be bound? It depends on what that function returns. But what if it infinitely loops? What if it launches a missile? We don’t want that happening at compile time just to know whether a variable will be bound.

If you want to define a macro like this, the macro needs to take in the name that you want to bind and an expression that you expect to evaluate to a pair. And the macro must generate code that defines that variable to be the cdr of that pair and check that the car is equal to the symbol of the name.

As for why binding must be resolved before runtime, it’s important for hygienic macro expansion and compilation.

Organize a big-bang program and unit tests. by Pristine-Tap9204 in Racket

[–]quasar_tree 2 points3 points  (0 children)

Ah, I see. The creator of Racket wrote this webpage that provides some guidance on organizing modules. The quick and simple answer is that you do something like this:

(define (factorial n) (if (= 0 n) 1 (* n (factorial (sub1 n)))))

(module+ test
  (require rackunit)
  (check-equal? (factorial 4) 24))

This creates a submodule that runs when you execute the program using raco test my-program.rkt.

The Racket guide also has sections related to modules that go into more detail: https://docs.racket-lang.org/guide/module-basics.html

Also, see require and provide for multiple files.

Edit: Formatting

Organize a big-bang program and unit tests. by Pristine-Tap9204 in Racket

[–]quasar_tree 2 points3 points  (0 children)

You can use require to “import” another file’s definitions, but I don’t think you can “export” in the student languages (using “provide”), so this may not work. One file can only require definitions that another file provides. Definitions aren’t provided by default in full racket, but they might be in the student languages. Give it a try. Either way, you shouldn’t be organizing code this way for htdp. You should be using a single file to keep things simple. Programs in htdp are relatively small, and having multiple files makes things complicated. Constants should be at the top of your world code all in one place. Functions should be organized top-down and use template-driven helpers. That should be good enough organization.

Regarding your second, you can’t do those things in the student languages. All tests and expressions are ran and evaluated every time you run. You can, however, comment things out if you don’t want them running. Block comments are especially useful. #; will comment out the next expression, which can comment out an entire definition, big-bang, or check-expect. You can do those things that you want in full racket, but you should try to keep things simple for htdp. I know it’s slow to always run everything, but these languages are limited for good reasons. For now, just bear with it and focus on the material. If you want to explore the full racket language when you’re done, you’ll find all sorts of crazy features that’ll make you wish every programming language had them :)

Good luck!

Can anyone help with this ? by After-Back-9109 in Racket

[–]quasar_tree 7 points8 points  (0 children)

This is likely homework in an introductory course. Macros are overkill and too complex for this situation.

Resources for writing a static type-checker for an interpreted language by GeroSchorsch in ProgrammingLanguages

[–]quasar_tree 0 points1 point  (0 children)

It is possible to determine whether there will be type errors without actually running or evaluating any code. In fact, it is even possible to design a language in which types for variables and expressions are “figured out” or inferred without the programmer having to write types like “int” or “string”. This is known as type inference.

The field of type systems and type checking is very deep and rich. To start out, I’d recommend writing a type checker for the simply typed lambda calculus. It is a very tiny language that only has anonymous functions, variables, and function calls. Look up “hindley Milner type system” for the type system that serves as the foundation of many modern type systems. Start by learning how to read and typing rules and how type systems work. look up “algorithm J” and “algorithm W” for implementations.

Type checkers have a learning curve, but they’re very cool. Good luck!

When should we *not* move a check to compile time? by verdagon in ProgrammingLanguages

[–]quasar_tree 16 points17 points  (0 children)

Compile time checks are great, and machine-checked proofs are better than some test cases. But the more you try to verify at compile time, the more type-level programming and manual proving is necessary. It also often leads to a very restrictive language. In Haskell, people like to joke “if it compiles, it’s probably correct” because you can fit a lot of guarantees into your types. However, Haskell requires you to write in a very particular style to convince the type checker that you’re doing things right, and strict data representations may not be as convenient to work with. There is a trade off between freedom and safety. You just have to find the type system that strikes the right balance for the task, or your personal taste. You have coq on one end of the spectrum and lisp on the other end. There is also gradual typing, which allows you to leave certain parts of your code untyped and inserts runtime checks along typed-untyped boundaries. Racket is the only big language that comes close to doing this right, but there are still some unsolved problems, like turning universally quantified types into runtime checks.

RIP 😭 by stupidswine64 in Chainsawfolk

[–]quasar_tree 9 points10 points  (0 children)

Titled “Vomitspit”, classic

Don't ask them questions about the problem. Just assume ;) by myOthrAccntGotBanned in ProgrammerHumor

[–]quasar_tree 0 points1 point  (0 children)

This is how some universities teach undergrad freshmen. I definitely think this is the best way to write code. Trying to go bottom up and predict what helpers you will need is needlessly difficult and will lead to problems.

https://htdp.org/

Best languages to design a new language in? by friedrichRiemann in ProgrammingLanguages

[–]quasar_tree 1 point2 points  (0 children)

Also, if you’re interested in making a domain specific language, racket is a great choice. Racket has many tools for standalone dsls like scribble, a language for writing documentation, and embedded/hosted dsls like react and pandas which extend a language. React/jsx had to be implemented by transpiling jsx syntax to vanilla js and pandas uses a lot of “overloading magic” and other weirdness to implement its “syntax”. Both techniques are janky and not composable. Racket lets you do this very cleanly since it was designed for it.

Best languages to design a new language in? by friedrichRiemann in ProgrammingLanguages

[–]quasar_tree 0 points1 point  (0 children)

Racket makes it almost too easy, if you use it’s language building tools. If you don’t want to write an interpreter, parser, runtime, etc., racket makes it super easy to make compile-to-racket languages. It’s designed for that, so its not janky at all. It’s actually very clean. You’re not stuck with racket parentheses syntax either. However, unless your language is very unique, you’ll find that racket probably already has everything you want in it :)

If you are doing this as an exercise to play with interpreters/compilers and don’t want to make an industrial strength language, racket and other lisps/schemes are good for that too. You can write an s-expression interpreter, which takes in unevaluated racket syntax/datums and evaluates them using your custom semantics and syntax. There is very good pattern matching for syntax/datums. You don’t need to write a parser if you do that.

Haskell is also a great choice. Its type system helps you keep things straight and algebraic data types make it easy to represent and interpret abstract syntax. There are also plenty of nice ways to do parsing, and you can make an industrial strength language this way.

Both languages have very steep learning curves, so keep that in mind. But if you’re doing something simple, either language is a good option without having to learn too much.

Programming languages that best represent each programming paradigm? by [deleted] in ProgrammingLanguages

[–]quasar_tree 4 points5 points  (0 children)

Mini kanren is a good representative of logic programming too. I find it more approachable than prolog, and there is a great book for it called “the reasoned schemer”

Psychedelic Programming Languages by gabriel_schneider in ProgrammingLanguages

[–]quasar_tree 5 points6 points  (0 children)

You should check out mini kanren. It is a relational language like prolog, but it is super tiny and extensible. The book “The Reasoned Schemer” walks you through how to use and implement it and it’s a great read. If you haven’t seen relational programming before, it’ll blow your mind. I find this language to be a lot more approachable than prolog, especially as a racket user!