scaledn icon indicating copy to clipboard operation
scaledn copied to clipboard

Design for Named (Symbol, Keyword, Tags)

Open ahoy-jon opened this issue 10 years ago • 4 comments

Currently the code have a special treatment for symbols, then Keyword and Tags are a "new type" of Symbol :

case class  EDNSymbol(value: String, namespace: Option[String] = None) extends EDNValue {
  override def toString = value
}

case class  EDNKeyword(value: EDNSymbol) extends EDNValue {
  override def toString = s":$value"
}

case class  EDNTagged[A](tag: EDNSymbol, value: A) extends EDNValue {
  override def toString = s"#$tag ${value.toString}"
}

I would say, the semantic behind is not quite like that, but more like :

case class Named(value: String, namespace: Option[String] = None) {
  override def toString = namespace.map(_ + "/" + value).getOrElse(value)
}

case class EDNSymbol (named: Named) extends EDNValue {
  override def toString = named
}

case class EDNKeyword(named: Named) extends EDNValue {
  override def toString = s":$named"
}

case class EDNTagged[A](tag: Named, value: A) extends EDNValue {
  override def toString s"#$named ${value.toString}"
}

It's a bit picky, but one advantage of that is you can write safe implicit conversion from String / Symbol to Named, then simplifying the EDN' AST construction.

EDNKeyword('ahoy) // ...

ahoy-jon avatar Dec 24 '14 21:12 ahoy-jon

Good proposition, I had questions about this part of AST anyway... In Datomisca, we had defined it more like that... I will push this update to see how it behaves...

mandubian avatar Dec 25 '14 10:12 mandubian

BTW, using the macro, you can create those symbol & keywords directly:

EDN(":myns.foo/bar")

mandubian avatar Dec 25 '14 10:12 mandubian

For information :

see #7 btw you can use : https://hub.github.com/hub.1.html and git pull-request -i 5 to transform an issue into a PR.

ahoy-jon avatar Jan 01 '15 23:01 ahoy-jon

Yes I know but I was too lazy between celebrations to install hub on my archlinux :D

On Fri, Jan 2, 2015 at 12:36 AM, Jonathan Winandy [email protected] wrote:

For information :

see #7 https://github.com/mandubian/scaledn/pull/7 btw you can use : https://hub.github.com/hub.1.html and git pull-request -i 5 to transform an issue into a PR.

— Reply to this email directly or view it on GitHub https://github.com/mandubian/scaledn/issues/5#issuecomment-68502391.

mandubian avatar Jan 02 '15 09:01 mandubian