How to fix the Unbound module Graphics in an ocaml project

Image
From ~/pr/gitl/ocaml-gol In a constant effort to learn new programming languages, I'm currently trying to use ocaml , a free and open-source general-purpose, multi-paradigm programming language maintained at the Inria . It's basically an extension of Caml with object-oriented features. I'm mostly interested by its functionnal and pattern matching features but the module part of the language can be a bit difficult to understand for someone with little to none ML (Meta Language) background.   The error When trying to use the graphics module to create a graphical window and go just a little further than the simplest helloworld program, here is the result : If the project uses dune : (executable (name ocaml_project) (libraries lwt.unix graphics) ) with this code : let () = Printf.printf "Hello, world!\n";; Lwt_io.printf "Hello, world!\n";; Graphics.open_graph " 800x600";; The first times I built this project running the du...

How to remove the first character of a ruby string

Recently, I had to remove the first character of string in a private nanoc-powered project.

 

Removing first char of a string in ruby

 I easily found a quick and elegant way to achieve this and according to this stackoverflow answer it seems the fastest.

  path="_theString"
  path[1..-1]  # => "theString"

And to complete this post, if you plan to use this often and you want to remove one or more leading letters, you may want to override the String class to remove the first n characters :
class String
  def removeFirstChars!(how_many = 1)
    self.replace self[how_many..-1]
  end
end

And you can use it on every String variable :

str="Aze"
str.removeFirstChars!
# => ze
#  or
str.removeFirstChars! 2
# => e

The stackoverflow answer also gives the code and benchmark results to achieve this with an Array In this initial post, the function is called eat and it shows several other useful utility functions.

Comments

Popular posts from this blog

How to make a map of variant in C++