REPLference.jl

This is a straightforward package designed to teach Julia to beginners in the Julia REPL. It provides an elegant method for locating methods that work on objects.
Author udohjeremiah
Popularity
13 Stars
Updated Last
1 Year Ago
Started In
February 2023
Repo Info
Repo Stats
Contributing

REPLference.jl

REPLference.jl is a package that addresses two challenges:

First, it provides materials for beginners to learn basic programming in Julia within Julia's versatile REPL. Instead of searching online or asking basic Julia questions elsewhere, beginners can use the rich-feature REPL to learn.

Second, it aims to solve the problem of accessing methods in Julia using the "dot" syntax, which can be frustrating for new users. In many OOP languages, users can easily see and learn new methods to call on an object by using the "dot" syntax in their editor, as shown in this example below:

Python example

However, in Julia, this isn't possible because a.x refers to the property x bundled with a, not the method x bundled with a (methods are not bundled with objects in Julia). So when users type a.<tab> in the REPL, it will return the properties defined in a, as shown in this example below:

Julia example

This limitation often leads to "reinventing the wheel" for those who can write the methods they're looking for and a "break in workflow" for those who cannot, as they have to go online to ask, "Is there a method X to do Y?" There is an ongoing discussion in Julia's discourse forum about this.

NOTE: Julia provides functions like methods, methodswith, and which to help users with this challenge, but new users may still struggle because these functions don't return an exhaustive list of methods.

Finally, for convenience, this package uses AbstractTrees.jl as a dependency to print the sub- and super-types of a type in a tree-like format.

Installing

To install and use, follow these steps:

julia> ] # enters the package mode
pkg> add REPLference

julia> using REPLference

If you enjoy using REPLference.jl, you can ensure that the package is automatically loaded in every Julia session without having to explicitly call using REPLference each time in the REPL. To do this, simply add the following line to your ~/.julia/config/startup.jl file (if the file does not exist, create it):

@eval using REPLference

Usage

This package provides three functions, and their usage is explained below.

NOTE: The examples below will be truncated to keep this README file concise.

man

You can think of man as a function that returns the manual for a topic or object in Julia.

To see the manual for an object, pass the object to man:

julia> a = 'J'
'J': ASCII/Unicode U+004A (category Lu: Letter, uppercase)

julia> man(a)
  CHARACTERS
  ≡≡≡≡≡≡≡≡≡≡≡≡

  When we refer to "characters" in computer programming, we are not necessarily limiting our view
  to the characters that most English speakers are familiar with. Some examples of these familiar
  characters include letters like A, B, C, etc., numbers 1, 2, 3, etc., and common punctuation
  

  julia> isvalid('\UD7FF')
  true
  
  julia> '\UD7FF'
  '\ud7ff': Unicode U+D7FF (category Cn: Other, not assigned)

If you're interested in seeing the manual for a topic, simply pass the topic as a Symbol, e.g., man(:characters). If an invalid topic is entered, nothing is printed to the screen.

fun

You can think of fun as a function that returns the names related to a topic or that can be called on a Julia object.

To see the names that can be called on an object, pass the object to fun:

julia> fun(a)
Macros
≡≡≡≡≡≡≡≡
@assert    @doc    @show    @showtime

Methods
≡≡≡≡≡≡≡≡≡

AbstractChar    Cchar    Char    Cuchar    Cwchar_t    DataType    Ref    Pair

Operators
≡≡≡≡≡≡≡≡≡≡≡
!     !==    +    <     ==    >     ^                                    ===
!=    *      -    <=    =>    >=                                     

You can pass a keyword argument named extmod::Bool to the function. The default value for extmod is false. If extmod is true, fun prints methods that can be called on the object, as well as methods from modules in the standard library that can be loaded with using or import:

julia> fun(a, extmod=true)
Macros
≡≡≡≡≡≡≡≡
@assert    @doc    @show    @showtime

Methods
≡≡≡≡≡≡≡≡≡


Stdlib
≡≡≡≡≡≡≡≡
Printf.@printf     Printf.Pointerˣ            Printf.formatˣ
Printf.@sprintf    Printf.PositionCounterˣ    Unicode.isassignedˣ
Printf.Formatˣ     Printf.Specˣ               Unicode.julia_chartransformˣ

If you're interested in seeing the functions for a topic, simply pass the topic as a Symbol, e.g., fun(:characters). If an invalid topic is entered, nothing is printed to the screen.

Names suffixed with ˣ are unexported. In cases where they are not qualified with a module, they need to be qualified with either Base, Core, or InteractiveUtils for the name to be available.

subtree

This function prints the subtypes of an object T in a tree format. T must be a Type; otherwise, an error is thrown.

julia> subtree(Integer)
Integer
├─ Bool
├─ Signed
│  ├─ BigInt
│  ├─ Int128
│  ├─ Int16
│  ├─ Int32
│  ├─ Int64
│  └─ Int8
└─ Unsigned
   ├─ UInt128
   ├─ UInt16
   ├─ UInt32
   ├─ UInt64
   └─ UInt8

Package Status

I regret to inform you that, due to time constraints, I am no longer able to maintain the package/repository in question. I have thoroughly enjoyed working on it and providing updates thus far.

However, I believe in the power of open-source collaboration and would like to offer an opportunity to anyone who is passionate about maintaining this package/repository to take over its ownership. If you are interested in becoming the new maintainer, kindly notify me, and I will gladly transfer ownership to you.

I appreciate your understanding and support throughout this journey. Thank you.

Required Packages

Used By Packages

No packages found.