News for hackers. Stuff that matters.
Re:Reading a Programmer's Guide to Common Lisp by ogogmad on Thursday February 22, 2024 @02:40PM (#39471988)
Python expresses destructuring bind using:

   x, y = foo, bar
It occasionally comes in handy. It certainly does suggest there's compatibility with VAR syntax.

Haskell's `do` notation also supports destructuring bind the Python way. It's even made into a special case of pattern matching. It also allows you to make declarations anywhere inside a block. This seems better than the Common Lisp approach.

Re:Reading a Programmer's Guide to Common Lisp by dannymi on Thursday February 22, 2024 @03:05PM (#39472363)
> It[Python] certainly does suggest there's compatibility with VAR syntax.

Maybe. Maybe not.

>It[Haskell, or do notation] also allows you to make declarations anywhere inside a block.

    main = do
        let x = 1
        let y = 2
        let z = 3
        let y = x
            z = y
            x = z
        print x

    => compilation error[1]
Do you find that normal?

How would you write what I wrote in Lisp in Haskell (for example using what you said)? Is it gonna need new concepts?

Compare:

    main = do
        let x = 1
        let y = 2
        let z = 3
        let y = x
        let z = y
        let x = z
        print [x, y, z]

    => [1, 1, 1] (as expected--but it's still dumb)
[1]

    a.hs:9:5: error:
        • Ambiguous type variable ‘a0’ arising from a use of ‘print’
          prevents the constraint ‘(Show a0)’ from being solved.
          Probable fix: use a type annotation to specify what ‘a0’ should be.
          These potential instances exist:
            instance Show Ordering -- Defined in ‘GHC.Show’
            instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
            instance Show Integer -- Defined in ‘GHC.Show’
            instance Show () -- Defined in ‘GHC.Show’
            instance (Show a, Show b) => Show (a, b) -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c) => Show (a, b, c)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d) => Show (a, b, c, d)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e) =>
                     Show (a, b, c, d, e)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e, Show f) =>
                     Show (a, b, c, d, e, f)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e, Show f,
                      Show g) =>
                     Show (a, b, c, d, e, f, g)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g,
                      Show h) =>
                     Show (a, b, c, d, e, f, g, h)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g,
                      Show h, Show i) =>
                     Show (a, b, c, d, e, f, g, h, i)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g,
                      Show h, Show i, Show j) =>
                     Show (a, b, c, d, e, f, g, h, i, j)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g,
                      Show h, Show i, Show j, Show k) =>
                     Show (a, b, c, d, e, f, g, h, i, j, k)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g,
                      Show h, Show i, Show j, Show k, Show l) =>
                     Show (a, b, c, d, e, f, g, h, i, j, k, l)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g,
                      Show h, Show i, Show j, Show k, Show l, Show m) =>
                     Show (a, b, c, d, e, f, g, h, i, j, k, l, m)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g,
                      Show h, Show i, Show j, Show k, Show l, Show m, Show n) =>
                     Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
              -- Defined in ‘GHC.Show’
            instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g,
                      Show h, Show i, Show j, Show k, Show l, Show m, Show n, Show o) =>
                     Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
              -- Defined in ‘GHC.Show’
            instance Show a => Show (Solo a) -- Defined in ‘GHC.Show’
            instance Show Bool -- Defined in ‘GHC.Show’
            instance Show Char -- Defined in ‘GHC.Show’
            instance Show Double -- Defined in ‘GHC.Float’
            instance Show Float -- Defined in ‘GHC.Float’
            instance Show Int -- Defined in ‘GHC.Show’
            instance Show Word -- Defined in ‘GHC.Show’
            instance Show a => Show [a] -- Defined in ‘GHC.Show’
            ...plus 13 instances involving out-of-scope types
              instance Show GHC.Stack.Types.CallStack -- Defined in ‘GHC.Show’
              instance Show GHC.Types.KindRep -- Defined in ‘GHC.Show’
              instance Show GHC.Types.Levity -- Defined in ‘GHC.Show’
              instance Show GHC.Types.Module -- Defined in ‘GHC.Show’
              instance Show GHC.Num.Natural.Natural -- Defined in ‘GHC.Show’
              instance Show a => Show (GHC.Base.NonEmpty a)
                -- Defined in ‘GHC.Show’
              instance Show GHC.Types.RuntimeRep -- Defined in ‘GHC.Show’
              instance Show GHC.Stack.Types.SrcLoc -- Defined in ‘GHC.Show’
              instance Show GHC.Types.TrName -- Defined in ‘GHC.Show’
              instance Show GHC.Types.TyCon -- Defined in ‘GHC.Show’
              instance Show GHC.Types.TypeLitSort -- Defined in ‘GHC.Show’
              instance Show GHC.Types.VecCount -- Defined in ‘GHC.Show’
              instance Show GHC.Types.VecElem -- Defined in ‘GHC.Show’
        • In a stmt of a 'do' block: print x
          In the expression:
            do let x = 1
               let y = 2
               let z = 3
               let y = x
                   z = y
                   ....
               ....
          In an equation for ‘main’:
              main
                = do let x = ...
                     let y = ...
                     let z = ...
                     ....
      |
    9 |     print x
      |     ^^^^^
^ Are you sure you want this in your language? :)
Re:Reading a Programmer's Guide to Common Lisp by tome on Thursday February 22, 2024 @05:13PM (#39474055)
> How would you write what I wrote in Lisp in Haskell

    main = do
        let x = 1
        let y = 2
        let z = 3
        let y' = x
            z' = y
            x' = z
        print [x', y', z']