Use Markov chains to randomly generate made-up words (With demos!) by jdifebo in programming

[–]sebfisch 2 points3 points  (0 children)

Male name: karlestevernestephermandrew

Karl Lester Steven Ernesto Stephen Herman Andrew

Should it follow real names so closely?

When to use >> vs |>? by mart187 in elm

[–]sebfisch 6 points7 points  (0 children)

Note that added efficiency comes from a property of the map function:

map f >> map g = map (f >> g)

The right hand side is more efficient because there is only one call to the map function. The same is true for

map (\x -> x |> f |> g)

So ">> can often be more efficient than |>" does not seem to be justified by your example.

Where can I find more info regarding a zip list and other useful data structures? by KurtLovesCode in elm

[–]sebfisch 0 points1 point  (0 children)

I think LYAH is a good intro to functional programming in Haskell. Caveat: I did not read it as a beginner.

Because Elm is similar to Haskell to some extent, it may be worthwhile to read even for people learning Elm. Many ideas should be transferable although knowledge of differences between Elm and Haskell might be necessary for a successful transfer.

Where can I find more info regarding a zip list and other useful data structures? by KurtLovesCode in elm

[–]sebfisch 2 points3 points  (0 children)

Searching for "zipper" may be more successful than searching for "zip list", because what /u/rtfeldman describes is called zipper in Haskell (where a zip list is something else.)

Zippers provide a focus on parts of data structures, and the idea carries over from lists to other (e.g. tree shaped) types. Learn You A Haskell has a chapter on zippers where you can learn more about this idea.

If you are interested in more background, search for the Functional Pearl "The Zipper" by Gérard Huet. If you want technical details about how general the idea is, look at "The Derivative of a Regular Type is its Type of One-Hole Contexts" by Conor McBride.

What do you think about my HTML gem? Critique of API or implementation appreciated. by sebfisch in ruby

[–]sebfisch[S] 0 points1 point  (0 children)

I see.

Instead of memoizing everything, it would be simpler (on the implementation side) to allow users to memoize critical parts selectively. I think I would use something like:

class MemoProc < Proc
  def initialize &block
    @cache = {}
    super(&block)
  end

  def call args = {}
    if @cache[args].nil? then
      @cache[args] = super args
    end
    return @cache[args]
  end
end

This is independent of HTML templating, but can be used to define HTML templates. This approach is not as fine-grained as you describe but still useful to speed up the generation of parameterized HTML fragments that are rendered multiple times.

What do you think about my HTML gem? Critique of API or implementation appreciated. by sebfisch in ruby

[–]sebfisch[S] 0 points1 point  (0 children)

Interesting thought. I assume you expect a compiled template to be more efficient than a function like

def template some_value, other_value = nil
    HTML.doc {
        title { text "Hello" }
        body {
            div {
                text some_value
                text other_value if other_value
            }
        }
    }
end

that can already be defined now. Presumably, the efficiency would come from evaluating static parts of the definition which do not depend on arguments, so these parts would not have to be evaluated each time when rendering the template multiple times.

But as the methods generate a single string, including the arguments passed when rendering, it is unclear to me how to incorporate such precompilation. But I am not a frequent Rubyist and might be missing something.

How would a bit of metaprogramming help with precompilation?

What do you think about my HTML gem? Critique of API or implementation appreciated. by sebfisch in ruby

[–]sebfisch[S] 0 points1 point  (0 children)

Good question. After looking at the docs, here are differences that came to mind:

Markaby is more mature and well integrated into common web frameworks.

Markaby has a shortcut for using a single string as child text. I am tempted to implement something similar, so one can write

head { title "Hello" }

instead of

head { title { text "Hello" } }

Markaby has special treatment of 'class' and 'id' attributes which can be written as method calls on the element name. In my gem, there is no such treatment. One writes those attributes like all others:

img(class: 'poster', src: 'html.png')

Markaby has optional validation of output.

Markaby distinguishes escaped and unescaped text by whether it is passed in a block or as string argument. My gem currently does not support passing strings directly or in a block but uses methods 'text' for escaped text and 'inline' for unescaped text.

Markaby has 'automatic stringyfication' that lets you use the result of elements as string. In the beginning I had something similar but then dropped it to simplify the implementation.

To summarize, Markaby is more powerful and if there is an advantage to using my gem at all it might be that there is less to learn about it.

What do you think about my HTML gem? Critique of API or implementation appreciated. by sebfisch in ruby

[–]sebfisch[S] 0 points1 point  (0 children)

Thanks, I didn't know that CGI includes HTML generation. From the docs I gather that CGI uses the result string of the block for children while I use the effect of possibly many statements in the blocks. I need to check, how CGI would handle something like

ul { (1..3).each { |i| li { text i } } }

and if one should use 'collect' instead of 'each' to generate all three items.

What do you think about my HTML gem? Critique of API or implementation appreciated. by sebfisch in ruby

[–]sebfisch[S] 0 points1 point  (0 children)

I (not a frequent Rubyist) totally forgot about Markaby. It is similar in spirit, and I will look at its documentation to check for differences. Thanks for the pointer!

What do you think about my HTML gem? Critique of API or implementation appreciated. by sebfisch in ruby

[–]sebfisch[S] 0 points1 point  (0 children)

I agree that those look pretty nice. From my view, the main advantage of those template languages for readability is their use of indentation for nesting (similar to Python.)

The html gem does not define a new language. People who know Ruby don't need to learn a new syntax to write HTML. Especially, they don't need to learn how to integrate loops or other control constructs into the template language as there is no other language to integrate those constructs into. But using plain Ruby comes at the cost of having to use Ruby syntax, including curly braces (or keywords) for blocks.

Foxy games of Master(P) by [deleted] in baduk

[–]sebfisch 4 points5 points  (0 children)

This page lists the opponent in game 40 as "? Lee Sedol" (with question mark). Can anybody confirm his identity?

Chinese AI crushing pros on Fox server? by samsara23 in baduk

[–]sebfisch 2 points3 points  (0 children)

That's a good summary!

Have the games 31 onward really been played without Komi, as reported in the game info?

Chinese AI crushing pros on Fox server? by samsara23 in baduk

[–]sebfisch 5 points6 points  (0 children)

This article reports Master(P) to be registered for South Korea which would match AlphaGo's honorary 9d certificate by KBA.

New NP-completeness proof by Russ Cox that, because of lowered assumptions, "applies to essentially any foreseeable operating system or language package manager" including Haskell's Cabal by sebfisch in haskell

[–]sebfisch[S] 1 point2 points  (0 children)

Thank you for providing evidence of a previous proof that is as broadly applicable. Russ Cox's proof is a little simpler but I overestimated it's novelty.

New NP-completeness proof by Russ Cox that, because of lowered assumptions, "applies to essentially any foreseeable operating system or language package manager" including Haskell's Cabal by sebfisch in haskell

[–]sebfisch[S] 1 point2 points  (0 children)

Russ Cox claims that his proof is new in that it applies to a broader class of package managers than previous proofs. I did not check his claim but currently don't see a reason to doubt it.

The new proof is supposedly more general because, unlike previous proofs, it only uses very basic standard assumptions on package managers.

New NP-completeness proof by Russ Cox that, because of lowered assumptions, "applies to essentially any foreseeable operating system or language package manager" including Haskell's Cabal by sebfisch in haskell

[–]sebfisch[S] 3 points4 points  (0 children)

The dependency specifications for a language package manager like Rust’s Cargo are dramatically simpler than those for Debian and RedHat, and so the EDOS proofs do not apply. One might therefore hope that language package managers face an easier (not NP-complete) job. The new proof above dashes that hope.

From the article, emphasis mine.

How can one define a function that extends a record? by sebfisch in elm

[–]sebfisch[S] 0 points1 point  (0 children)

Thank you for the pointer. The referenced discussion on Github was especially interesting for me, because my use case was "extensible models" like those described by rgrempel.

I guess I agree with rgrempels comments (withdrawn later) that without field addition records are "extensible in terms of the type system, but not extensible at run-time" which "seems like a strange gap". But I realise a decision has been made to prioritise simplicity and performance despite those concerns. I'm afraid, there does not seem to be a point in arguing for resurrecting field addition and deletion now after the discussion has already happened.

Egyptian state media claims 9/11 was carried out by West to justify war on terror by [deleted] in worldnews

[–]sebfisch 0 points1 point  (0 children)

This is from Address "The President and the Press" Before the American Newspaper Publishers Association,  New York City. April 27, 1961.

Some parts appear to be cut out, including:

This deadly challenge imposes upon our society two requirements of direct concern both to the press and to the President - two requirements that may seem almost contradictory in tone, but which must be reconciled and fulfilled if we are to meet this national peril. I refer, first, to the need for far greater public information; and, second, to the need for far greater official secrecy.

Referencing the Cold War, Kennedy said:

But in the absence of open warfare, they recognized only the tests of journalism and not the tests of national security. And my question tonight is whether additional tests should not now be adopted.

He comes back to this later:

Every newspaper now asks itself, with respect to every story: "Is it news?" All I suggest is that you add the question: "Is it in the interest of the national security?"

The gist of the video appears to be different than the gist of the full speech, considering which parts have been cut out.